var site_table = bt_tools.table({
  el: '#bt_site_table',
  url: '/data?action=getData',
  cookiePrefix: 'site_table', // cookie前缀，用于状态存储，如果不设置，着所有状态不存储，
  param: {
    table: 'sites'
  }, //参数
  minWidth: '1000px',
  autoHeight: true,
  default: "站点列表为空", // 数据为空时的默认提示
  beforeRequest: function (param) {
    param.type = bt.get_cookie('site_type') || -1;
    return param;
  },
  column: [{
      type: 'checkbox',
      width: 20
    },
    {
      fid: 'name',
      title: '网站名',
      sort: true,
      sortValue: 'asc',
      type: 'link',
      event: function (row, index, ev) {
        site.web_edit(row, true);
      }
    },
    {
      fid: 'status',
      title: '状态',
      sort: true,
      width: 98,
      config: {
        icon: true,
        list: [
          ['1', '运行中', 'bt_success', 'glyphicon-play'],
          ['正常', '运行中', 'bt_success', 'glyphicon-play'],
          ['正在运行', '运行中', 'bt_success', 'glyphicon-play'],
          ['0', '已停止', 'bt_danger', 'glyphicon-pause']
        ]
      },
      type: 'status',
      event: function (row, index, ev, key, that) {
        bt.site[parseInt(row.status) ? 'stop' : 'start'](row.id, row.name, function (res) {
          if (res.status) that.$modify_row_data({
            status: parseInt(row.status) ? '0' : '1'
          });
        });
      }
    },
    {
      fid: 'backup_count',
      title: '备份',
      width: 90,
      type: 'link',
      template: function (row, index) {
        var backup = '点击备份',
          _class = "bt_warning";
        if (row.backup_count > 0) backup = lan.site.backup_yes, _class = "bt_success";
        return '<a href="javascript:;" class="btlink  ' + _class + '">' + backup + (row.backup_count > 0 ? ('(' + row.backup_count + ')') : '') + '</a>';
      },
      event: function (row, index) {
        site.site_detail(row.id, row.name, 1, $(this).parents('tr').index());
      }
    },
    {
      fid: 'type_version',
      title: 'PHP',
      width: 90,
      type: 'link',
      template: function (row, index) {
        var type = row.type,
          version = row.type_version,
          html = '';
        if (type == 'PHP') {
          if (version == -1) {
            html = '未知版本'
          } else if (version === '00') {
            html = '纯静态';
          } else {
            html = '<a href="javascript:;" class="btlink">' + type + '-' + version + '</a>';
          }
        } else {
          html = '<span>' + type + '</span>';
        }
        return html;
      },
      event: function (row, index) {
        if (row.type == 'PHP' && row.type_version != -1) {
          site.web_edit(row);
          setTimeout(function () {
            $('.site-menu p:eq(11)').click();
          }, 500);
        }
      }
    },
    {
      fid: 'path',
      title: '根目录',
      type: 'link',
      event: function (row, index, ev) {
        openPath(row.path);
      }
    },
    {
      fid: 'edate',
      title: '到期时间',
      width: 85,
      class: 'set_site_edate',
      sort: true,
      type: 'link',
      template: function (row, index) {
        var _endtime = '';
        if (row.edate) _endtime = row.edate;
        if (row.endtime) _endtime = row.endtime;
        _endtime = (_endtime === "0000-00-00") ? lan.site.web_end_time : _endtime;
        return _endtime;
      },
      event: function (ev) {
        console.log(ev);
      }
    }, // 模拟点击效果
    {
      fid: 'ps',
      title: '备注',
      type: 'input',
      blur: function (row, index, ev) {
        bt.pub.set_data_ps({
          id: row.id,
          table: 'sites',
          ps: ev.target.value
        }, function (res) {
          layer.msg(res.msg, (res.status ? {} : {
            icon: 2
          }));
        });
      },
      keyup: function (row, index, ev) {
        if (ev.keyCode === 13) {
          $(this).blur();
        }
      }
    },
    // (bt.os == 'Linux'?{
    //     field: 'id', title: '防火墙', templet: function (item) {
    //         var _check = ' onclick="site.no_firewall(this)"';
    //         if (item.waf_setup) _check = ' onclick="set_site_obj_state(\'' + item.name + '\',\'open\')"';
    //         var _waf = '<input class="btswitch btswitch-ios " ' + _check + ' id="closewaf_' + item.name + '" ' + (item.firewall ? 'checked' : '') + ' type="checkbox">';
    //         _waf += '<label class="btswitch-btn bt-waf-firewall" for="closewaf_' + item.name + '" title="' + bt.get_cookie('serverType') + '防火墙开关"></label>';
    //         return _waf;
    //     }
    // } :{}),
    {
      title: '操作',
      type: 'group',
      width: 150,
      align: 'right',
      group: [{
        title: '设置',
        event: function (row, index, ev, key, that) {
          site.web_edit(row, true);
        }
      }, {
        title: '删除',
        event: function (row, index, ev, key, that) {
          site.del_site(row.id, row.name, function (res) {
            if (res.status) that.$refresh_table_list(true);
          });
        }
      }]
    }
  ],
  sortParam: function (data) {
    return {
      'order': data.name + ' ' + data.sort
    };
  },
  // 表格渲染完成后
  success: function (that) {
    $('.event_edate_' + that.random).each(function () {
      var $this = $(this);
      laydate.render({
        elem: $this[0] //指定元素
          ,
        min: bt.get_date(1),
        max: '2099-12-31',
        vlue: bt.get_date(365),
        type: 'date',
        format: 'yyyy-MM-dd',
        trigger: 'click',
        btns: ['perpetual', 'confirm'],
        theme: '#20a53a',
        ready: function () {
          $this.click();
        },
        done: function (date) {
          var item = that.event_rows_model.rows;
          bt.site.set_endtime(item.id, date, function (res) {
            if (res.status) {
              layer.msg(res.msg);
              return false;
            }
            bt.msg(res);
          });
        }
      });
    });
  },
  // 渲染完成
  tootls: [{ // 按钮组
    type: 'group',
    positon: ['left', 'top'],
    list: [{
        title: '添加站点',
        active: true,
        event: function (ev) {
          site.add_site(function () {
            site_table.$refresh_table_list(true)
          });
          bt.set_cookie('site_type', '-1');
        }
      },
      {
        title: '修改默认页',
        event: function (ev) {
          site.set_default_page()
        }
      },
      {
        title: '默认站点',
        event: function (ev) {
          site.set_default_site()
        }
      }
    ]
  }, { // 搜索内容
    type: 'search',
    positon: ['right', 'top'],
    placeholder: '请输入域名或备注',
    searchParam: 'search', //搜索请求字段，默认为 search
    value: '', // 当前内容,默认为空
  }, { // 批量操作
    type: 'batch', //batch_btn
    positon: ['left', 'bottom'],
    placeholder: '请选择批量操作',
    buttonValue: '批量操作',
    disabledSelectValue: '请选择需要批量操作的站点!',
    selectList: [{
      title: '开启站点',
      url: '/site?action=SiteStart',
      param: {
        status: 1
      },
      confirmVerify: false, //是否提示验证方式
      paramName: 'id', //列表参数名,可以为空
      paramId: 'id', // 需要传入批量的id
      theadName: '站点名称',
      refresh: true
    }, {
      title: "停止站点",
      url: '/site?action=SiteStop',
      param: {
        status: 0
      },
      confirmVerify: false, //是否提示验证方式
      paramName: 'id', //列表参数名,可以为空
      paramId: 'id',
      load: true,
      theadName: '站点名称',
      refresh: true
    }, {
      title: "备份站点",
      url: '/site?action=ToBackup',
      paramId: 'id',
      load: true,
      theadName: '站点名称',
      callback: function (that) { // 手动执行,data参数包含所有选中的站点
        bt.confirm({
          title: '批量备份站点',
          msg: '是否备份选中的站点？',
          icon: 2
        }, function () {
          that.start_batch({}, function (list) {
            var html = '';
            for (var i = 0; i < list.length; i++) {
              var item = list[i];
              html += '<tr><td>' + item.name + '</td><td><div style="float:right;"><span style="color:' + (item.request.status ? '#20a53a' : 'red') + '">' + item.request.msg + '</span></div></td></tr>';
            }
            site_table.$batch_success_table({
              title: '批量备份',
              th: '站点名称',
              html: html
            });
            site_table.$refresh_table_list(true);
          });
        });
      }
    }, {
      title: "设置到期时间",
      url: '/site?action=SetEdate',
      paramName: 'id', //列表参数名,可以为空
      paramId: 'id', // 需要传入批量的id
      theadName: '站点名称',
      refresh: true,
      confirm: {
        title: '批量设置到期时间',
        content: '<div class="line"><span class="tname">到期时间</span><div class="info-r "><input name="edate" id="site_edate" class="bt-input-text mr5" placeholder="yyyy-MM-dd" type="text"></div></div>',
        success: function () {
          laydate.render({
            elem: '#site_edate',
            min: bt.format_data(new Date().getTime(), 'yyyy-MM-dd'),
            max: '2099-12-31',
            vlue: bt.get_date(365),
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger: 'click',
            btns: ['perpetual', 'confirm'],
            theme: '#20a53a'
          });
        },
        yes: function (index, layers, request) {
          var site_edate = $('#site_edate'),
            site_edate_val = site_edate.val();
          if (site_edate_val != '') {
            request({
              'edate': site_edate_val === '永久' ? '0000-00-00' : site_edate_val
            });
          } else {
            layer.tips('请输入到期时间', '#site_edate', {
              tips: ['1', 'red']
            });
            $('#site_edate').css('border-color', 'red');
            $('#site_edate').click();
            setTimeout(function () {
              $('#site_edate').removeAttr('style');
            }, 3000);
            return false;
          }
        }
      }
    }, {
      title: "设置PHP版本",
      url: '/site?action=SetPHPVersion',
      paramName: 'siteName', //列表参数名,可以为空
      paramId: 'name', // 需要传入批量的id
      theadName: '站点名称',
      refresh: true,
      screening: function (index, row) {
        console.log(row.type.indexOf('Asp'), row);
        if (row.type.indexOf('Asp') > -1) {
          return false;
        }
      },
      confirm: {
        title: '批量设置PHP版本',
        area: '420px',
        content: '<div class="line"><span class="tname">PHP版本</span><div class="info-r"><select class="bt-input-text mr5 versions" name="versions" style="width:150px"></select></span></div><ul class="help-info-text c7" style="font-size:11px"><li>请根据您的程序需求选择版本</li><li>若非必要,请尽量不要使用PHP5.2,这会降低您的服务器安全性；</li><li>PHP7不支持mysql扩展，默认安装mysqli以及mysql-pdo。</li><li style="color:red;">Aspx和Asp程序无法切换，请须知</li></ul></div>',
        success: function () {
          bt.site.get_all_phpversion(function (res) {
            var html = '';
            $.each(res, function (index, item) {
              html += '<option value="' + item.version + '">' + item.name + '</option>';
            });
            $('[name="versions"]').html(html);
          });
        },
        yes: function (index, layers, request) {
          request({
            version: $('[name="versions"]').val()
          });
        }
      }
    }, {
      title: "设置分类",
      url: '/site?action=set_site_type',
      paramName: 'site_ids', //列表参数名,可以为空
      paramId: 'id', // 需要传入批量的id
      refresh: true,
      beforeRequest: function (list) {
        var arry = [];
        $.each(list, function (index, item) {
          arry.push(item.id);
        });
        return JSON.stringify(arry);
      },
      confirm: {
        title: '批量设置分类',
        content: '<div class="line"><span class="tname">站点分类</span><div class="info-r"><select class="bt-input-text mr5 site_types" name="site_types" style="width:150px"></select></span></div></div>',
        success: function () {
          bt.site.get_type(function (res) {
            var html = '';
            $.each(res, function (index, item) {
              html += '<option value="' + item.id + '">' + item.name + '</option>';
            });
            $('[name="site_types"]').html(html);
          });
        },
        yes: function (index, layers, request) {
          request({
            id: $('[name="site_types"]').val()
          });
        }
      },
      tips: false,
      success: function (res, list, that) {
        var html = '';
        $.each(list, function (index, item) {
          html += '<tr><td>' + item.name + '</td><td><div style="float:right;"><span style="color:' + (res.status ? '#20a53a' : 'red') + '">' + res.msg + '</span></div></td></tr>';
        });
        that.$batch_success_table({
          title: '批量设置分类',
          th: '站点名称',
          html: html
        });
        site_table.$refresh_table_list(true);
      }
    }, {
      title: "恢复网站到IIS",
      url: '/site?action=sync_iis_site',
      paramName: 'ids', //列表参数名,可以为空
      paramId: 'id', // 需要传入批量的id
      refresh: true,
      beforeRequest: function (list) {
        var arry = [];
        $.each(list, function (index, item) {
          arry.push(item.id);
        });
        return JSON.stringify(arry);
      },
      confirmVerify: true,
      tableName: '站点名称'
    }, {
      title: "删除站点",
      url: '/site?action=DeleteSite',
      load: true,
      param: function (row) {
        return {
          id: row.id,
          webname: row.name
        }
      },
      callback: function (that) { // 手动执行,data参数包含所有选中的站点
        bt.show_confirm("批量删除站点", "是否同时删除选中站点同名的FTP、数据库、根目录", function () {
          var param = {};
          $('.bacth_options input[type=checkbox]').each(function () {
            var checked = $(this).is(":checked");
            if (checked) param[$(this).attr('name')] = checked ? 1 : 0;
          })
          that.start_batch(param, function (list) {
            var html = '';
            for (var i = 0; i < list.length; i++) {
              var item = list[i];
              html += '<tr><td>' + item.name + '</td><td><div style="float:right;"><span style="color:' + (item.request.status ? '#20a53a' : 'red') + '">' + item.request.msg + '</span></div></td></tr>';
            }
            site_table.$batch_success_table({
              title: '批量删除',
              th: '站点名称',
              html: html
            });
            site_table.$refresh_table_list(true);
          });
        }, "<div class='options bacth_options'><label><input type='checkbox' name='ftp'><span>FTP</span></label><label><input type='checkbox' name='database'><span>" + lan.site.database + "</span></label><label><input type='checkbox' name='path'><span>" + lan.site.root_dir + "</span></label></div>");
      }
    }],
  }, { //分页显示
    type: 'page',
    positon: ['right', 'bottom'], // 默认在右下角
    pageParam: 'p', //分页请求字段,默认为 : p
    page: 1, //当前分页 默认：1
    numberParam: 'limit', //分页数量请求字段默认为 : limit
    number: 20, //分页数量默认 : 20条
    numberList: [10, 20, 50, 100, 200], // 分页显示数量列表
    numberStatus: true, //　是否支持分页数量选择,默认禁用
    jump: true, //是否支持跳转分页,默认禁用
  }]
});
$('.tootls_group.tootls_top .pull-left').append('<div class="bt_select_updown site_class_type"><div class="bt_select_value"><span class="bt_select_content">分类:</span><span class="glyphicon glyphicon-triangle-bottom ml5"></span></span></div><ul class="bt_select_list"></ul></div>');
bt.site.get_type(function (res) {
  site.reader_site_type(res);
});
var site = {
  reader_site_type: function (res) {
    var html = '',
      active = bt.get_cookie('site_type') || -1,
      select = $('.site_class_type');
    res.unshift({
      id: -1,
      name: "全部分类"
    });
    $.each(res, function (index, item) {
      html += '<li class="item ' + (parseInt(active) == item.id ? 'active' : '') + '" data-id="' + item.id + '">' + item.name + '</li>';
    });
    html += '<li role="separator" class="divider"></li><li class="item" data-id="type_sets">分类设置</li>';
    select.find('.bt_select_value').on('click', function (ev) {
      var $this = this;
      $(this).next().show();
      $(document).one('click', function () {
        $($this).next().hide();

      });
      ev.stopPropagation()
    });

    select.find('.bt_select_list').unbind('click').on('click', 'li', function () {
      var id = $(this).data('id');
      if (id == 'type_sets') {
        site.set_class_type();
      } else {
        bt.set_cookie('site_type', id);
        site_table.$refresh_table_list(true);
        $(this).addClass('active').siblings().removeClass('active');
        select.find('.bt_select_value .bt_select_content').text('分类: ' + $(this).text());
      }

    }).empty().html(html);
    if (!select.find('.bt_select_list li.active').length) {
      select.find('.bt_select_list li:eq(0)').addClass('active');
      select.find('.bt_select_value .bt_select_content').text('分类: 默认分类');
    } else {
      select.find('.bt_select_value .bt_select_content').text('分类: ' + select.find('.bt_select_list li.active').text());
    }
  },
  get_list: function (page, search, type) {
    if (page == undefined) page = 1;
    if (type == '-1' || type == undefined) {
      type = $('.site_type select').val();
    }
    search = search || $('#SearchValue').val();
    bt.site.get_list(page, search, type, function (rdata) {
      $('.dataTables_paginate').html(rdata.page);
      var _tab = bt.render({
        table: '#webBody',
        columns: [{
            field: 'id',
            type: 'checkbox',
            width: 30
          },
          {
            field: 'name',
            title: '网站名',
            width: 150,
            templet: function (item) {
              return '<a class="btlink webtips" onclick="site.web_edit(this)" href="javascript:;">' + item.name + '</a>';
            },
            sort: function () {
              site.get_list();
            }
          },

          {
            field: 'status',
            title: '状态',
            width: 98,
            templet: function (item) {
              var _status = '<a href="javascript:;" ';
              if (item.status == '1' || item.status == '正常' || item.status == '正在运行') {
                _status += ' onclick="bt.site.stop(' + item.id + ',\'' + item.name + '\') " >';
                _status += '<span style="color:#5CB85C">运行中 </span><span style="color:#5CB85C" class="glyphicon glyphicon-play"></span>';
              } else {
                _status += ' onclick="bt.site.start(' + item.id + ',\'' + item.name + '\')"';
                _status += '<span style="color:red">已停止  </span><span style="color:red" class="glyphicon glyphicon-pause"></span>';
              }
              return _status;
            },
            sort: function () {
              site.get_list();
            }
          },
          {
            field: 'backup',
            title: '备份',
            width: 90,
            templet: function (item) {
              var backup = '<span style="color:#e5804e">点击备份</span>';
              if (item.backup_count > 0) backup = '有备份(' + item.backup_count + ')';
              return '<a href="javascript:;" class="btlink" onclick="site.site_detail(' + item.id + ',\'' + item.name + '\')">' + backup + '</a>';
            }
          },
          {
            field: 'type_version',
            title: '程序类型',
            width: 90,
            templet: function (item) {

              var ver = item.type
              if (ver == 'PHP') {
                if (item.type_version == -1) {
                  ver = '未知版本'
                } else {
                  ver = '<a href="javascript:;" class="btlink" onclick="site.open_site_program_type(this)">' + ver + '-' + item.type_version + '</a>';
                }
              }

              return ver
            }
          },
          {
            field: 'path',
            title: '根目录',
            width: '26%',
            templet: function (item) {
              var _path = bt.format_path(item.path);
              return '<a class="btlink" title="打开目录" href="javascript:openPath(\'' + _path + '\');">' + _path + '</a>';
            }
          },
          {
            field: 'edate',
            title: '到期时间',
            width: 86,
            templet: function (item) {
              var _endtime = '';
              if (item.edate) _endtime = item.edate;
              if (item.endtime) _endtime = item.endtime;
              _endtime = (_endtime == "0000-00-00") ? lan.site.web_end_time : _endtime
              return '<a class="btlink setTimes" id="site_endtime_' + item.id + '" >' + _endtime + '</a>';
            },
            sort: function () {
              site.get_list();
            }
          },
          {
            field: 'ps',
            title: '备注',
            templet: function (item) {
              return "<span class='c9 input-edit'  onclick=\"bt.pub.set_data_by_key('sites','ps',this)\">" + item.ps + "</span>";
            }
          },
          bt.os == 'Linux' ? {
            field: 'id',
            title: '防火墙',
            templet: function (item) {
              var _check = ' onclick="site.no_firewall(this)"';
              if (item.waf_setup) _check = ' onclick="set_site_obj_state(\'' + item.name + '\',\'open\')"';
              var _waf = '<input class="btswitch btswitch-ios " ' + _check + ' id="closewaf_' + item.name + '" ' + (item.firewall ? 'checked' : '') + ' type="checkbox">';
              _waf += '<label class="btswitch-btn bt-waf-firewall" for="closewaf_' + item.name + '" title="' + bt.get_cookie('serverType') + '防火墙开关"></label>';
              return _waf;
            }
          } : '',
          {
            field: 'opt',
            width: 260,
            title: '操作',
            align: 'right',
            templet: function (item) {
              var opt = '';
              var _check = ' onclick="site.site_waf(\'' + item.name + '\')"';

              if (bt.os == "Linux") opt += '<a href="javascript:;" ' + _check + ' class="btlink ">防火墙</a> | ';
              opt += '<a href="javascript:;" class="btlink" onclick="site.web_edit(this)">设置 </a> | ';
              opt += '<a href="javascript:;" class="btlink" onclick="site.del_site(' + item.id + ',\'' + item.name + '\')" title="删除站点">删除</a>';
              return opt;
            }
          },
        ],
        data: rdata.data
      })

      if (bt.get_cookie('serverType') == 'iis') {
        $(".btn-sync_iis").show();
      }

      //设置到期时间
      $('a.setTimes').each(function () {
        var _this = $(this);
        var _tr = _this.parents('tr');
        var id = _this.attr('id');
        laydate.render({
          elem: '#' + id //指定元素
            ,
          min: bt.get_date(1),
          max: '2099-12-31',
          vlue: bt.get_date(365),
          type: 'date',
          format: 'yyyy-MM-dd',
          trigger: 'click',
          btns: ['perpetual', 'confirm'],
          theme: '#20a53a',
          done: function (dates) {
            var item = _tr.data('item');
            bt.site.set_endtime(item.id, dates, function () {})
          }
        });
      })
    })
  },
  open_site_program_type: function (that) {
    site.web_edit(that);
    setTimeout(function () {
      site.reload(11);
    }, 500);
  },
  html_encode: function (html) {
    var temp = document.createElement("div");
    //2.然后将要转换的字符串设置为这个元素的innerText(ie支持)或者textContent(火狐，google支持)
    (temp.textContent != undefined) ? (temp.textContent = html) : (temp.innerText = html);
    //3.最后返回这个元素的innerHTML，即得到经过HTML编码转换的字符串了
    var output = temp.innerHTML;
    temp = null;
    return output;
  },
  get_types: function (callback) {
    bt.site.get_type(function (rdata) {
      var optionList = '';
      for (var i = 0; i < rdata.length; i++) {
        optionList += '<option value="' + rdata[i].id + '">' + rdata[i].name + '</option>'
      }
      if ($('.dataTables_paginate').next().hasClass('site_type')) $('.site_type').remove();
      $('.dataTables_paginate').after('<div class="site_type"><span>站点分类:</span><select class="bt-input-text mr5"  style="width:100px"><option value="-1">全部分类</option>' + optionList + '</select></div>');
      $('.site_type select').change(function () {
        var val = $(this).val();
        site.get_list(0, '', val);
        bt.set_cookie('site_type', val);
      })
      if (callback) callback(rdata);
    });
  },
  no_firewall: function (obj) {
    var typename = bt.get_cookie('serverType');
    layer.confirm(typename + '防火墙暂未开通，<br>请到&quot;<a href="/soft" class="btlink">软件管理>付费插件>' + typename + '防火墙</a>&quot;<br>开通安装使用。', {
      title: typename + '防火墙未开通',
      icon: 7,
      closeBtn: 2,
      cancel: function () {
        if (obj) $(obj).prop('checked', false)
      }
    }, function () {
      window.location.href = '/soft';
    }, function () {
      if (obj) $(obj).prop('checked', false)
    })
  },
  site_detail: function (id, siteName, page) {
    if (page == undefined) page = '1';
    var loadT = bt.load(lan.public.the_get);
    bt.pub.get_data('table=backup&search=' + id + '&limit=5&type=0&tojs=site.site_detail&p=' + page, function (frdata) {
      loadT.close();
      var ftpdown = '';
      var body = '';
      var port;
      frdata.page = frdata.page.replace(/'/g, '"').replace(/site.site_detail\(/g, "site.site_detail(" + id + ",'" + siteName + "',");
      if ($('#SiteBackupList').length <= 0) {
        bt.open({
          type: 1,
          skin: 'demo-class',
          area: '700px',
          title: lan.site.backup_title + '【' + siteName + '】',
          closeBtn: 2,
          shift: 5,
          shadeClose: false,
          content: "<div class='divtable pd15 style='padding-bottom: 0'><button id='btn_data_backup' class='btn btn-success btn-sm' type='button' style='margin-bottom:10px'>" + lan.database.backup + "</button><table width='100%' id='SiteBackupList' class='table table-hover'></table><div class='page sitebackup_page'></div></div>"
        });
      }
      setTimeout(function () {
        $('.sitebackup_page').html(frdata.page);
        var _tab = bt.render({
          table: '#SiteBackupList',
          columns: [{
              field: 'name',
              title: '文件名称'
            },
            {
              field: 'size',
              title: '文件大小',
              templet: function (item) {
                return bt.format_size(item.size);
              }
            },
            {
              field: 'addtime',
              title: '备份时间'
            },
            {
              field: 'opt',
              title: '操作',
              align: 'right',
              templet: function (item) {
                var _opt = '<a class="btlink" href="/download?filename=' + item.filename + '&amp;name=' + item.name + '" target="_blank">下载</a> | ';
                _opt += '<a class="btlink" herf="javascrpit:;" onclick="bt.site.del_backup(\'' + item.id + '\',\'' + id + '\',\'' + siteName + '\')">删除</a>'
                return _opt;
              }
            },
          ],
          data: frdata.data
        });
        $('#btn_data_backup').unbind('click').click(function () {
          bt.site.backup_data(id, function (rdata) {
            if (rdata.status) site.site_detail(id, siteName);
          })
        })
      }, 100)
    });
  },
  add_site: function (callback) {
    bt.site.add_site(function (rdata) {
      if (rdata.siteStatus) {
        if (callback) callback(rdata);
        site.get_list();
        var html = '';
        var ftpData = '';
        if (rdata.ftpStatus) {
          var list = [];
          list.push({
            title: lan.site.user,
            val: rdata.ftpUser
          });
          list.push({
            title: lan.site.password,
            val: rdata.ftpPass
          });
          var item = {};
          item.title = lan.site.ftp;
          item.list = list;
          ftpData = bt.render_ps(item);
        }
        var sqlData = '';
        if (rdata.databaseStatus) {
          var list = [];
          list.push({
            title: lan.site.database_name,
            val: rdata.databaseUser
          });
          list.push({
            title: lan.site.user,
            val: rdata.databaseUser
          });
          list.push({
            title: lan.site.password,
            val: rdata.databasePass
          });
          var item = {};
          item.title = lan.site.database_txt;
          item.list = list;
          sqlData = bt.render_ps(item);
        }
        if (ftpData == '' && sqlData == '') {
          bt.msg({
            msg: lan.site.success_txt,
            icon: 1
          })
        } else {
          bt.open({
            type: 1,
            area: '600px',
            title: lan.site.success_txt,
            closeBtn: 2,
            shadeClose: false,
            content: "<div class='success-msg'><div class='pic'><img src='/static/img/success-pic.png'></div><div class='suc-con'>" + ftpData + sqlData + "</div></div>",
          });

          if ($(".success-msg").height() < 150) {
            $(".success-msg").find("img").css({
              "width": "150px",
              "margin-top": "30px"
            });
          }
        }
      } else {
        bt.msg(rdata);
      }
    })
  },
  set_default_page: function () {
    bt.open({
      type: 1,
      area: '460px',
      title: lan.site.change_defalut_page,
      closeBtn: 2,
      shift: 0,
      content: '<div class="change-default pd20"><button  class="btn btn-default btn-sm ">' + lan.site.default_doc + '</button><button  class="btn btn-default btn-sm">' + lan.site.err_404 + '</button>	<button  class="btn btn-default btn-sm ">' + lan.site.empty_page + '</button><button  class="btn btn-default btn-sm ">' + lan.site.default_page_stop + '</button></div>'
    });
    setTimeout(function () {
      $('.change-default button').click(function () {
        bt.site.get_default_path($(this).index(), function (path) {
          bt.pub.on_edit_file(0, path);
        })
      })
    }, 100)
  },
  set_default_site: function () {
    bt.site.get_default_site(function (rdata) {
      var arrs = [{
        title: lan.site.default_site_no,
        value: 'off'
      }];
      for (var i = 0; i < rdata.sites.length; i++) arrs.push({
        title: rdata.sites[i].name,
        value: rdata.sites[i].name
      })
      var form = {
        title: lan.site.default_site_yes,
        area: ['530px', '230px'],
        list: [{
          title: lan.site.default_site,
          name: 'defaultSite',
          width: '300px',
          value: rdata.defaultSite,
          type: 'select',
          items: arrs
        }],
        btns: [
          bt.form.btn.close(),
          bt.form.btn.submit('提交', function (rdata, load) {
            bt.site.set_default_site(rdata.defaultSite, function (rdata) {
              load.close();
              bt.msg(rdata);
            })
          })
        ]
      }
      bt.render_form(form);
      $('.line').after($(bt.render_help([lan.site.default_site_help_1, lan.site.default_site_help_2])).css({
        'bottom': '60px'
      }).addClass('plr20'));
    })
  },
  del_site: function (wid, wname, callback) {
    var thtml = "<div class='options'><label><input type='checkbox' id='delftp' name='ftp'><span>FTP</span></label><label><input type='checkbox' id='deldata' name='data'><span>" + lan.site.database + "</span></label><label><input type='checkbox' id='delpath' name='path'><span>" + lan.site.root_dir + "</span></label></div>";
    bt.show_confirm(lan.site.site_del_title + "[" + wname + "]", lan.site.site_del_info, function () {
      var ftp = '',
        data = '',
        path = '';
      var data = {
        id: wid,
        webname: wname
      }
      if ($("#delftp").is(":checked")) data.ftp = 1;
      if ($("#deldata").is(":checked")) data.database = 1;
      if ($("#delpath").is(":checked")) data.path = 1;
      bt.site.del_site(data, function (rdata) {
        if (rdata.status) site.get_list();
        if (callback) callback(rdata);
        bt.msg(rdata);
      })

    }, thtml);
  },
  batch_site: function (type, obj, result) {
    if (obj == undefined) {
      obj = {};
      var arr = [];
      result = {
        count: 0,
        error_list: []
      };
      $('input[type="checkbox"].check:checked').each(function () {
        var _val = $(this).val();
        if (!isNaN(_val)) arr.push($(this).parents('tr').data('item'));
      })
      if (type == 'site_type') {
        bt.site.get_type(function (tdata) {
          var types = [];
          for (var i = 0; i < tdata.length; i++) types.push({
            title: tdata[i].name,
            value: tdata[i].id
          })
          var form = {
            title: '设置站点分类',
            area: '530px',
            list: [{
              title: lan.site.default_site,
              name: 'type_id',
              width: '300px',
              type: 'select',
              items: types
            }],
            btns: [
              bt.form.btn.close(),
              bt.form.btn.submit('提交', function (rdata, load) {
                var ids = []
                for (var x = 0; x < arr.length; x++) ids.push(arr[x].id);
                bt.site.set_site_type({
                  id: rdata.type_id,
                  site_array: JSON.stringify(ids)
                }, function (rrdata) {
                  if (rrdata.status) {
                    load.close();
                    site.get_list();
                  }
                  bt.msg(rrdata);
                })
              })
            ]
          }
          bt.render_form(form);
        })
        return;
      }
      var thtml = "<div class='options'><label style=\"width:100%;\"><input type='checkbox' id='delpath' name='path'><span>" + lan.site.all_del_info + "</span></label></div>";
      bt.show_confirm(lan.site.all_del_site, "<a style='color:red;'>" + lan.get('del_all_site', [arr.length]) + "</a>", function () {
        if ($("#delpath").is(":checked")) obj.path = '1';
        obj.data = arr;
        bt.closeAll();
        site.batch_site(type, obj, result);
      }, thtml);

      return;
    }
    var item = obj.data[0];
    switch (type) {
      case 'del':
        if (obj.data.length < 1) {
          site.get_list();
          bt.msg({
            msg: lan.get('del_all_site_ok', [result.count]),
            icon: 1,
            time: 5000
          });
          return;
        }
        var data = {
          id: item.id,
          webname: item.name,
          path: obj.path
        }
        bt.site.del_site(data, function (rdata) {
          if (rdata.status) {
            result.count += 1;
          } else {
            result.error_list.push({
              name: item.item,
              err_msg: rdata.msg
            });
          }
          obj.data.splice(0, 1)
          site.batch_site(type, obj, result);
        })
        break;

    }
  },
  set_class_type: function () {
    var _form_data = bt.render_form_line({
      title: '',
      items: [{
          placeholder: '请填写分类名称',
          name: 'type_name',
          width: '50%',
          type: 'text'
        },
        {
          name: 'btn_submit',
          text: '添加',
          type: 'button',
          callback: function (sdata) {
            bt.site.add_type(sdata.type_name, function (ldata) {
              if (ldata.status) {
                $('[name="type_name"]').val('');
                site.get_class_type();
              }
              bt.msg(ldata);
            })
          }
        }
      ]
    });
    bt.open({
      type: 1,
      area: '350px',
      title: '网站分类管理',
      closeBtn: 2,
      shift: 5,
      shadeClose: true,
      content: "<div class='bt-form edit_site_type'><div class='divtable mtb15' style='overflow:auto'>" + _form_data.html + "<table id='type_table' class='table table-hover' width='100%'></table></div></div>",
      success: function () {
        bt.render_clicks(_form_data.clicks);
        site.get_class_type(function (res) {
          $('#type_table').on('click', '.del_type', function () {
            var _this = $(this);
            var item = _this.parents('tr').data('item');
            if (item.id == 0) {
              bt.msg({
                icon: 2,
                msg: '默认分类不可删除/不可编辑!'
              });
              return;
            }
            bt.confirm({
              msg: "是否确定删除分类？",
              title: '删除分类【' + item.name + '】'
            }, function () {
              bt.site.del_type(item.id, function (ret) {
                if (ret.status) {
                  site.get_class_type();
                  bt.set_cookie('site_type', '-1');
                }
                bt.msg(ret);
              })
            })
          });
          $('#type_table').on('click', '.edit_type', function () {
            var item = $(this).parents('tr').data('item');
            if (item.id == 0) {
              bt.msg({
                icon: 2,
                msg: '默认分类不可删除/不可编辑!'
              });
              return;
            }
            bt.render_form({
              title: '修改分类管理【' + item.name + '】',
              area: '350px',
              list: [{
                title: '分类名称',
                width: '150px',
                name: 'name',
                value: item.name
              }],
              btns: [{
                  title: '关闭',
                  name: 'close'
                },
                {
                  title: '提交',
                  name: 'submit',
                  css: 'btn-success',
                  callback: function (rdata, load, callback) {
                    bt.site.edit_type({
                      id: item.id,
                      name: rdata.name
                    }, function (edata) {
                      if (edata.status) {
                        load.close();
                        site.get_class_type();
                      }
                      bt.msg(edata);
                    })
                  }
                }
              ]
            });
          });
        });
      }
    });
  },
  get_class_type: function (callback) {
    site.get_types(function (rdata) {
      bt.render({
        table: '#type_table',
        columns: [{
            field: 'name',
            title: '名称'
          },
          {
            field: 'opt',
            width: '80px',
            title: '操作',
            templet: function (item) {
              return '<a class="btlink edit_type" href="javascript:;">编辑</a> | <a class="btlink del_type" href="javascript:;">删除</a>';
            }
          }
        ],
        data: rdata
      });
      $('.layui-layer-page').css({
        'margin-top': '-' + ($('.layui-layer-page').height() / 2) + 'px',
        'top': '50%'
      });
      site.reader_site_type(rdata);
      if (callback) callback(rdata);
    });
  },
  pool: {
    reload: function (index) {
      if (index == undefined) index = 0
      var _sel = $('#pool_tabs .on');
      if (_sel.length == 0) _sel = $('#pool_tabs span:eq(0)');
      _sel.trigger('click');
    }
  },
  ssl: {
    my_ssl_msg: null,
    my_select_domain_ssl_index: null,
      /**
   * @description 设置域名信息
   * @Date: 2021-03-31 17:05:38
   * @param {*} oid
   * @return {*}
   */                    
      setupDomainInfo: function (oid, domains, path){
        var html = '';
        for (var i = 0; i < domains.length; i++) {
          var item = domains[i];
          html += '<option value="' + item.value + '">' + item.title + '</option>';
        }
        bt.open({
          type: 1,
          title: '申请宝塔SSL证书',
          area:'520px',
          btn:['确认','取消'],
          content:'<div class="bt-form pd20"><div class="line">\
              <span class="tname">域名</span>\
              <div class="info-r"><select class="bt-input-text mr5 " name="domain" style="width:280px">' + html + '</select></div>\
            </div>\
            <ul class="help-info-text-info c7" style="position: relative;">\
              <li>申请之前，请确保域名已解析，如未解析会导致审核失败(包括根域名)</li>\
              <li>宝塔SSL申请的是TrustAsia DV SSL CA - G5证书，仅支持单个域名申请</li>\
              <li>有效期1年，不支持续签，到期后需要重新申请</li><li>建议使用二级域名为www的域名申请证书,此时系统会默认赠送顶级域名为可选名称</li>\
              <li>在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点</li>\
              <li>宝塔SSL申请注意事项及教程 <a href="https://www.bt.cn/bbs/thread-33113-1-1.html" target="_blank" class="btlink"> 使用帮助</a></li><li><span style="color:red">IIS8.5以下版本，一台服务器只能存在一个SSL，多次部署会替换之前的SSL</span></li></ul>\
          </div>',
          yes:function(){
              bt_tools.send('ssl/apply_order_byca', { ssl_id: oid, domain: $('[name="domain"]').val(), path: path},function (res) {
              bt.msg(res);
            },{plugin:true,load:'申请证书'});
          }
        });
      },
    /**
     * @description 证书caa解析验证
     * @param {*} data 
     */
    ssl_caa_verify: function (data) {
      var data = JSON.parse(data),
        arry = [];
      if (!Array.isArray(data) && typeof data == "object") {
        $.each(data, function (key, item) {
          $.each(item, function (index, items) {
            arry.push($.extend(items, {
              domain: key,
              type: 'CAA记录'
            }));
          });
        });
      }
      bt.open({
        title: 'CAA记录检测',
        area: '500px',
        content: '<div class="pd15">' +
          '<div class="important-title" style="margin-bottom:10px">' +
          '<p><span class="glyphicon glyphicon-alert">&nbsp;检测到以下域名存在CAA记录，请手动删除，并重新申请。</span></p>' +
          '</div>' +
          '<div id="bt_caa_table"></div>' +
          '<ul class="help-info-text c7" style="font-size:13px;"><li>删除记录请到该域名对应的域名服务商，删除域名的CAA解析记录。</li></ul>' +
          '</div>',
        success: function () {
          var caa_table = bt_tools.table({
            el: '#bt_caa_table',
            data: arry,
            column: [{
                fid: 'domain',
                title: '域名'
              },
              {
                fid: 'type',
                title: '记录类型'
              },
              {
                fid: 'value',
                title: '记录值'
              }
            ]
          })
        }
      });
    },
    //续签订单内
    renew_ssl: function (siteName, auth_type, index) {
      acme.siteName = siteName;
      if (index.length === 32 && index.indexOf('/') === -1) {
        acme.renew(index, function (rdata) {
          site.ssl.ssl_result(rdata, auth_type, siteName)
        });
      } else {
        acme.get_cert_init(index, siteName, function (cert_init) {
          acme.domains = cert_init.dns;
          var options = '<option value="http">文件验证 - HTTP</option>';
          for (var i = 0; i < cert_init.dnsapi.length; i++) {
            options += '<option value="' + cert_init.dnsapi[i].name + '">DNS验证 - ' + cert_init.dnsapi[i].title + '</option>';
          }
          acme.select_loadT = layer.open({
            title: '续签Let\'s Encrypt证书',
            type: 1,
            closeBtn: 2,
            shade: 0.3,
            area: "500px",
            offset: "30%",
            content: '<div style="margin: 10px;">\
                                    <div class="line ">\
                                        <span class="tname" style="padding-right: 15px;margin-top: 8px;">请选择验证方式</span>\
                                        <div class="info-r label-input-group ptb10">\
                                            <select class="bt-input-text" name="auth_to">' + options + '</select>\
                                            <span class="dnsapi-btn"></span>\
                                            <span class="renew-onkey"><button class="btn btn-success btn-sm mr5" style="margin-left: 10px;" onclick="site.ssl.renew_ssl_other()">一键续签</button></span>\
                                        </div>\
                                    </div>\
                                    <ul class="help-info-text c7">\
                                        <li>通配符证书不能使用【文件验证】，请选择DNS验证</li>\
                                        <li>使用【文件验证】，请确保没有开[启强制HTTPS/301重定向/反向代理]等功能</li>\
                                        <li>使用【阿里云DNS】【DnsPod】等验证方式需要设置正确的密钥</li>\
                                        <li>续签成功后，证书将在下次到期前30天尝试自动续签</li>\
                                        <li>使用【DNS验证 - 手动解析】续签的证书无法实现下次到期前30天自动续签</li>\
                                    </ul>\
                                  </div>',
            success: function (layers) {
              $("select[name='auth_to']").change(function () {
                var dnsapi = $(this).val();
                $(".dnsapi-btn").html('');
                for (var i = 0; i < cert_init.dnsapi.length; i++) {
                  if (cert_init.dnsapi[i].name !== dnsapi) continue;
                  acme.dnsapi = cert_init.dnsapi[i]
                  if (!cert_init.dnsapi[i].data) continue;
                  $(".dnsapi-btn").html('<button class="btn btn-default btn-sm mr5 set_dns_config" onclick="site.ssl.show_dnsapi_setup()">设置</button>');
                  if (cert_init.dnsapi[i].data[0].value || cert_init.dnsapi[i].data[1].value) break;
                  site.ssl.show_dnsapi_setup();
                }
              });
            }
          });
        });
      }
    },
    //续签其它
    renew_ssl_other: function () {
      var auth_to = $("select[name='auth_to']").val()
      var auth_type = 'http'
      if (auth_to === 'http') {
        if (JSON.stringify(acme.domains).indexOf('*.') !== -1) {
          layer.msg("包含通配符的域名不能使用文件验证(HTTP)!", {
            icon: 2
          });
          return;
        }
        auth_to = acme.id
      } else {
        if (auth_to !== 'dns') {
          if (auth_to === "Dns_com") {
            acme.dnsapi.data = [{
              value: "None"
            }, {
              value: "None"
            }];
          }
          if (!acme.dnsapi.data[0].value || !acme.dnsapi.data[1].value) {
            layer.msg("请先设置【" + acme.dnsapi.title + "】接口信息!", {
              icon: 2
            });
            return;
          }
          auth_to = auth_to + '|' + acme.dnsapi.data[0].value + '|' + acme.dnsapi.data[1].value;
        }
        auth_type = 'dns'
      }
      layer.close(acme.select_loadT);
      acme.apply_cert(acme.domains, auth_type, auth_to, '0', function (rdata) {
        site.ssl.ssl_result(rdata, auth_type, acme.siteName);
      });
    },
    show_dnsapi_setup: function () {
      var dnsapi = acme.dnsapi;
      acme.dnsapi_loadT = layer.open({
        title: '设置【' + dnsapi.title + '】接口',
        type: 1,
        closeBtn: 0,
        shade: 0.3,
        area: "550px",
        offset: "30%",
        content: '<div class="bt-form bt-form pd20 pb70 ">\
                            <div class="line ">\
                                <span class="tname" style="width: 125px;">' + dnsapi.data[0].key + '</span>\
                                <div class="info-r" style="margin-left:120px">\
                                    <input name="' + dnsapi.data[0].name + '" class="bt-input-text mr5 dnsapi-key" type="text" style="width:330px" value="' + dnsapi.data[0].value + '">\
                                </div>\
                            </div>\
                            <div class="line ">\
                                <span class="tname" style="width: 125px;">' + dnsapi.data[1].key + '</span>\
                                <div class="info-r" style="margin-left:120px">\
                                    <input name="' + dnsapi.data[1].name + '" class="bt-input-text mr5 dnsapi-token" type="text" style="width:330px" value="' + dnsapi.data[1].value + '">\
                                </div>\
                            </div>\
                            <div class="bt-form-submit-btn">\
                                <button type="button" class="btn btn-sm btn-danger" onclick="layer.close(acme.dnsapi_loadT);">关闭</button>\
                                <button type="button" class="btn btn-sm btn-success dnsapi-save">保存</button>\
                            </div>\
                            <ul class="help-info-text c7">\
                                <li>' + dnsapi.help + '</li>\
                            </ul>\
                          </div>',
        success: function (layers) {
          $(".dnsapi-save").click(function () {
            var dnsapi_key = $(".dnsapi-key");
            var dnsapi_token = $(".dnsapi-token");
            pdata = {}
            pdata[dnsapi_key.attr("name")] = dnsapi_key.val();
            pdata[dnsapi_token.attr("name")] = dnsapi_token.val();
            acme.dnsapi.data[0].value = dnsapi_key.val();
            acme.dnsapi.data[1].value = dnsapi_token.val();
            bt.site.set_dns_api({
              pdata: JSON.stringify(pdata)
            }, function (ret) {
              if (ret.status) layer.close(acme.dnsapi_loadT);
              bt.msg(ret);
            });
          });
        }
      });
    },
    set_cert: function (siteName, res) {
      var loadT = bt.load(lan.site.saving_txt);
      var pdata = {
        type: 1,
        siteName: siteName,
        key: res.private_key,
        csr: res.cert + res.root
      }
      bt.send('SetSSL', 'site/SetSSL', pdata, function (rdata) {
        loadT.close();
        site.reload();
        layer.msg(res.msg, {
          icon: 1
        });
      })
    },
    show_error: function (res, auth_type) {
      var area_size = '500px';
      var err_info = "";

      if (!res.msg[1].challenges[1]) {
        if (res.msg[1].challenges[0]) {
          res.msg[1].challenges[1] = res.msg[1].challenges[0]
        }
      }
      if (res.msg[1].status === 'invalid') {
        area_size = '600px';
        var trs = $("#dns_txt_jx tbody tr");
        var dns_value = "";

        for (var imd = 0; imd < trs.length; imd++) {
          if (trs[imd].outerText.indexOf(res.msg[1].identifier.value) == -1) continue;
          var s_tmp = trs[imd].outerText.split("\t")
          if (s_tmp.length > 1) {
            dns_value = s_tmp[1]
            break;
          }
        }

        err_info += "<p><span>验证域名:</span>" + res.msg[1].identifier.value + "</p>"
        if (auth_type === 'dns') {
          var check_url = "_acme-challenge." + res.msg[1].identifier.value
          err_info += "<p><span>验证解析:</span>" + check_url + "</p>"
          err_info += "<p><span>验证内容:</span>" + dns_value + "</p>"
          err_info += "<p><span>错误代码:</span>" + site.html_encode(res.msg[1].challenges[1].error.detail) + "</p>"
        } else {
          var check_url = "http://" + res.msg[1].identifier.value + '/.well-known/acme-challenge/' + res.msg[1].challenges[0].token
          err_info += "<p><span>验证URL:</span><a class='btlink' href='" + check_url + "' target='_blank'>点击查看</a></p>"
          err_info += "<p><span>验证内容:</span>" + res.msg[1].challenges[0].token + "</p>"
          err_info += "<p><span>错误代码:</span>" + site.html_encode(res.msg[1].challenges[0].error.detail) + "</p>"
        }
        err_info += "<p><span>验证结果:</span> <a style='color:red;'>验证失败</a></p>"

        layer.msg('<div class="ssl-file-error"><a style="color: red;font-weight: 900;">' + res.msg[0] + '</a>' + err_info + '</div>', {
          icon: 2,
          time: 0,
          shade: 0.3,
          shadeClose: true,
          area: area_size
        });
      }
    },
    ssl_result: function (res, auth_type, siteName) {
      layer.close(acme.loadT);
      if (res.status === false && typeof (res.msg) === 'string') {
        bt.msg(res);
        return;
      }
      if (res.status === true || res.status === 'pending' || res.save_path !== undefined) {
        if (auth_type == 'dns' && res.status === 'pending') {
          var b_load = bt.open({
            type: 1,
            area: ['700px', '500px'],
            title: '手动解析TXT记录',
            closeBtn: 2,
            shift: 5,
            shadeClose: false,
            content: "<div class='divtable pd15 div_txt_jx' style='height:100%'>\
                                    <p class='mb15' >请按以下列表做TXT解析:</p>\
                                    <table id='dns_txt_jx' class='table table-hover'></table>\
                                    <div class='text-right mt10'>\
                                        <button class='btn btn-success btn-sm btn_check_txt' >验证</button>\
                                    </div>\
                                    </div>"
          });

          //手动验证事件
          $('.btn_check_txt').click(function () {
            acme.auth_domain(res.index, function (res1) {
              layer.close(acme.loadT);
              if (res1.status === true) {
                b_load.close();
                site.ssl.set_cert(siteName, res1)
              } else {
                site.ssl.show_error(res1, auth_type);
              }
            })

          });

          //显示手动验证信息
          setTimeout(function () {
            var data = [];
            acme_txt = '_acme-challenge.'
            for (var j = 0; j < res.auths.length; j++) {
              data.push({
                name: acme_txt + res.auths[j].domain.replace('*.', ''),
                type: "TXT",
                txt: res.auths[j].auth_value,
                force: "是"
              });
              data.push({
                name: res.auths[j].domain.replace('*.', ''),
                type: "CAA",
                txt: '0 issue "letsencrypt.org"',
                force: "否"
              });
            }
            bt.render({
              table: '#dns_txt_jx',
              columns: [{
                  field: 'name',
                  width: '220px',
                  title: '解析域名'
                },
                {
                  field: 'txt',
                  title: '记录值'
                },
                {
                  field: 'type',
                  title: '类型'
                },
                {
                  field: 'force',
                  title: '必需'
                }
              ],
              data: data
            })
            $('.div_txt_jx').append(bt.render_help([
              '解析域名需要一定时间来生效,完成所以上所有解析操作后,请等待1分钟后再点击验证按钮',
              '可通过CMD命令来手动验证域名解析是否生效: nslookup -q=txt ' + acme_txt + res.auths[0].domain.replace('*.', ''),
              '若您使用的是宝塔云解析插件,阿里云DNS,DnsPod作为DNS,可使用DNS接口自动解析'
            ]));
          });
          return;
        }
        site.ssl.set_cert(siteName, res)
        return;
      }

      site.ssl.show_error(res, auth_type);
    },
    get_renew_stat: function () {
      $.post('/ssl?action=Get_Renew_SSL', {}, function (task_list) {
        if (!task_list.status) return;
        var s_body = '';
        var b_stat = false;
        for (var i = 0; i < task_list.data.length; i++) {
          s_body += '<p>' + task_list.data[i].subject + ' >> ' + task_list.data[i].msg + '</p>';
          if (task_list.data[i].status !== true && task_list.data[i].status !== false) {
            b_stat = true;
          }
        }

        if (site.ssl.my_ssl_msg) {
          $(".my-renew-ssl").html(s_body);
        } else {
          site.ssl.my_ssl_msg = layer.msg('<div class="my-renew-ssl">' + s_body + '</div>', {
            time: 0,
            icon: 16,
            shade: 0.3
          });
        }

        if (!b_stat) {
          setTimeout(function () {
            layer.close(site.ssl.my_ssl_msg);
            site.ssl.my_ssl_msg = null;
          }, 3000);
          return;
        }

        setTimeout(function () {
          site.ssl.get_renew_stat();
        }, 1000);


      });
    },
    onekey_ssl: function (partnerOrderId, siteName) {
      bt.site.get_ssl_info(partnerOrderId, siteName, function (rdata) {
        rdata.time = 0;
        bt.msg(rdata);
        if (rdata.status) site.reload(7);
      })
    },
    set_ssl_status: function (action, siteName) {
      bt.site.set_ssl_status(action, siteName, function (rdata) {
        bt.msg(rdata);
        if (rdata.status) {
          site.reload(7);
          if (action == 'CloseSSLConf') {
            layer.msg(lan.site.ssl_close_info, {
              icon: 1,
              time: 5000
            });
          }
        }
      })
    },
    verify_domain: function (partnerOrderId, siteName) {
      bt.site.verify_domain(partnerOrderId, siteName, function (vdata) {
        bt.msg(vdata);
        if (vdata.status) {
          if (vdata.data.stateCode == 'COMPLETED') {
            site.ssl.onekey_ssl(partnerOrderId, siteName)
          } else {
            layer.msg('验证中,请等待CA机构验证,如第一次申请失败，请等待3小时或进入宝塔后台通过DNS方式验证.', {
              icon: 1,
              time: 0
            });
          }
        }
      })
    },
    reload: function (index) {
      if (index == undefined) index = 0
      var _sel = $('#ssl_tabs .on');
      if (_sel.length == 0) _sel = $('#ssl_tabs span:eq(0)');
      _sel.trigger('click');
    }
  },
  edit: {
    set_domains: function (web) {
      var _this = this;
      var list = [{
        items: [{
            name: 'newdomain',
            width: '340px',
            type: 'textarea',
            placeholder: '每行填写一个域名，默认为80端口<br>泛解析添加方法 *.domain.com<br>如另加端口格式为 www.domain.com:88'
          },
          {
            name: 'btn_submit_domain',
            text: '添加',
            type: 'button',
            callback: function (sdata) {
              var arrs = sdata.newdomain.split("\n");
              var domins = "";
              for (var i = 0; i < arrs.length; i++) domins += arrs[i] + ",";
              bt.site.add_domains(web.id, web.name, bt.rtrim(domins, ','), function (ret) {
                if (ret.status) site.reload(0)
              })
            }
          }
        ]
      }]
      var _form_data = bt.render_form_line(list[0]),
        loadT = null,
        placeholder = null;
      $('#webedit-con').html(_form_data.html + "<div class='bt_table' id='domain_table'></div>");
      bt.render_clicks(_form_data.clicks);
      $('.btn_submit_domain').addClass('pull-right').css("margin", "30px 35px 0 0");
      placeholder = $(".placeholder");
      placeholder.click(function () {
        $(this).hide();
        $('.newdomain').focus();
      }).css({
        'width': '340px',
        'heigth': '100px',
        'left': '0px',
        'top': '0px',
        'padding-top': '10px',
        'padding-left': '15px'
      })
      $('.newdomain').focus(function () {
        placeholder.hide();
        loadT = layer.tips(placeholder.html(), $(this), {
          tips: [1, '#20a53a'],
          time: 0,
          area: $(this).width()
        });
      }).blur(function () {
        if ($(this).val().length == 0) placeholder.show();
        layer.close(loadT);
      });
      var site_table = bt_tools.table({
        el: '#domain_table',
        url: '/data?action=getData',
        param: {
          table: 'domain',
          list: 'True',
          search: web.id
        },
        dataFilter: function (res) {
          return {
            data: res
          };
        },
        column: [{
            type: 'checkbox',
            width: 20
          },
          {
            fid: 'name',
            title: '域名',
            template: function (row) {
              return '<a href="http://' + row.name + ':' + row.port + '" target="_blank" class="btlink">' + row.name + '</a>';
            }
          },
          {
            fid: 'port',
            title: '端口',
            width: 50,
            type: 'text'
          },
          {
            title: '操作',
            width: 80,
            type: 'group',
            align: 'right',
            group: [{
              title: '删除',
              template: function (row, that) {
                return that.data.length === 1 ? '<span>不可操作</span>' : '删除';
              },
              event: function (row, index, ev, key, that) {
                if (that.data.length === 1) {
                  bt.msg({
                    status: false,
                    msg: '最后一个域名不能删除!'
                  });
                  return false;
                }
                bt.confirm({
                  title: '删除域名【' + row.name + '】',
                  msg: lan.site.domain_del_confirm
                }, function () {
                  bt.site.del_domain(web.id, web.name, row.name, row.port, function (res) {
                    if (res.status) that.$delete_table_row(index);
                    bt.msg(res);
                  });
                });
              }
            }]
          }
        ],
        tootls: [{ // 批量操作
          type: 'batch',
          positon: ['left', 'bottom'],
          config: {
            title: '删除',
            url: '/site?action=DelDomain',
            param: function (row) {
              return {
                domain: row.name,
                port: row.port
              }
            },
            callback: function (that) {
              bt.confirm({
                title: '批量删除域名',
                msg: '是否批量删除选中的域名？',
                icon: 2
              }, function () {
                that.start_batch({
                  id: web.id,
                  webname: web.name,
                  batch: true
                }, function (list) {
                  var html = '';
                  for (var i = 0; i < list.length; i++) {
                    var item = list[i];
                    html += '<tr><td>' + item.name + '</td><td><div style="float:right;"><span style="color:' + (item.request.status ? '#20a53a' : 'red') + ';white-space: pre;">' + item.request.msg + '</span></div></td></tr>';
                  }
                  site_table.$batch_success_table({
                    title: '批量删除域名',
                    th: '站点域名',
                    html: html
                  });
                  site_table.$refresh_table_list(true);
                });
              });
            }
          }
        }]
      });
    },
    set_dirbind: function (web) {
      var _this = this;
      bt.site.get_dirbind(web.id, function (rdata) {
        var dirs = [];
        for (var n = 0; n < rdata.dirs.length; n++) dirs.push({
          title: rdata.dirs[n],
          value: rdata.dirs[n]
        });
        var data = {
          title: '',
          items: [{
              title: '域名',
              width: '140px',
              name: 'domain'
            },
            {
              title: '子目录',
              name: 'dirName',
              type: 'select',
              items: dirs
            },
            {
              text: '添加',
              type: 'button',
              name: 'btn_add_subdir',
              callback: function (sdata) {
                if (!sdata.domain || !sdata.dirName) {
                  layer.msg(lan.site.d_s_empty, {
                    icon: 2
                  });
                  return;
                }
                if (sdata.domain.indexOf("*") >= 0 && bt.get_cookie("serverType") == 'iis') {
                  bt.msg({
                    msg: 'IIS不支持泛解析，如需使用，请通过设置默认站点实现。',
                    icon: 2,
                    time: 0
                  });
                  return;
                }
                bt.site.add_dirbind(web.id, sdata.domain, sdata.dirName, function (ret) {
                  if (ret.status) site.reload(1)
                  bt.msg(ret);
                })
              }
            }
          ]
        }
        var _form_data = bt.render_form_line(data);
        $('#webedit-con').html(_form_data.html + '<div class="divtable mtb15" style="height:450px;overflow:auto"><table id="sub_dir_table" class="table table-hover" width="100%" style="margin-bottom:0"></table></div>');
        bt.render_clicks(_form_data.clicks);
        bt.render({
          table: '#sub_dir_table',
          columns: [{
              field: 'domain',
              title: '域名'
            },
            {
              field: 'port',
              width: '70px',
              title: '端口'
            },
            {
              field: 'path',
              width: '100px',
              title: '子目录'
            },
            {
              field: 'opt',
              width: '100px',
              align: 'right',
              title: '操作',
              templet: function (item) {
                return '<a class="btlink rewrite" href="javascript:;">伪静态</a> | <a class="btlink del" href="javascript:;">删除</a>';
              }
            }
          ],
          data: rdata.binding
        })
        setTimeout(function () {
          $('#sub_dir_table td a').click(function () {
            var item = $(this).parents('tr').data('item');
            if ($(this).hasClass('del')) {
              bt.confirm({
                msg: lan.site.s_bin_del
              }, function () {
                bt.site.del_dirbind(item.id, function (ret) {
                  if (ret.status) site.reload(1)
                })
              })
            } else {
              bt.site.get_dir_rewrite({
                id: item.id
              }, function (ret) {
                if (!ret.status) {
                  var confirmObj = layer.confirm(lan.site.url_rewrite_alter, {
                    icon: 3,
                    closeBtn: 2
                  }, function () {
                    bt.site.get_dir_rewrite({
                      id: item.id,
                      add: 1
                    }, function (ret) {
                      layer.close(confirmObj);
                      show_dir_rewrite(ret);
                    });
                  });
                  return;
                }
                show_dir_rewrite(ret);

                function show_dir_rewrite(ret) {
                  var arrs = [];
                  for (var i = 0; i < ret.rlist.length; i++) arrs.push({
                    title: ret.rlist[i],
                    value: ret.rlist[i]
                  });
                  var datas = [{
                      name: 'dir_rewrite',
                      type: 'select',
                      width: '130px',
                      items: arrs,
                      callback: function (obj) {
                        var spath = setup_path + '/panel/rewrite/' + bt.get_cookie('serverType') + '/' + obj.val() + '.conf';
                        bt.files.get_file_body(spath, function (sdata) {
                          $('.dir_config').text(sdata.data);
                        })
                      }
                    },
                    {
                      items: [{
                        name: 'dir_config',
                        type: 'textarea',
                        value: ret.data,
                        width: '470px',
                        height: '260px'
                      }]
                    },
                    {
                      items: [{
                        name: 'btn_save',
                        text: '保存',
                        type: 'button',
                        callback: function (ldata) {
                          if (bt.os == "Linux") {
                            bt.files.set_file_body(ret.filename, ldata.dir_config, 'utf-8', function (sdata) {
                              if (sdata.status) load_form.close();
                              bt.msg(sdata);
                            })
                          } else {
                            var loading = bt.load();
                            bt.site.set_site_rewrite(web.name + '_' + item.path, ldata.dir_config, function (sdata) {
                              loading.close();
                              if (sdata.status) load_form.close();
                              bt.msg(sdata);
                            })
                          }
                        }
                      }]
                    }
                  ]
                  var load_form = bt.open({
                    type: 1,
                    area: '510px',
                    title: lan.site.config_url,
                    closeBtn: 2,
                    shift: 5,
                    skin: 'bt-w-con',
                    shadeClose: true,
                    content: "<div class='bt-form webedit-dir-box dir-rewrite-man-con'></div>"
                  });

                  setTimeout(function () {
                    var _html = $(".webedit-dir-box")
                    var clicks = [];
                    for (var i = 0; i < datas.length; i++) {
                      var _form_data = bt.render_form_line(datas[i]);
                      _html.append(_form_data.html);
                      var _other = (bt.os == 'Linux' && i == 0) ? '<span>规则转换工具：<a href="https://www.bt.cn/Tools" target="_blank" style="color:#20a53a">Apache转Nginx</a></span>' : '';
                      _html.find('.info-r').append(_other)
                      clicks = clicks.concat(_form_data.clicks);
                    }
                    _html.append(bt.render_help(['请选择您的应用，若设置伪静态后，网站无法正常访问，请尝试设置回default', '您可以对伪静态规则进行修改，修改完后保存即可。']));
                    bt.render_clicks(clicks);
                  }, 100)
                }
              })
            }
          })
        }, 100)
      })
    },
    //禁用脚本
    set_en_script: function (siteName, name, status) {
      status = status ? 1 : 0;
      var loading = bt.load();
      bt.send("set_en_script", "site/set_en_script", {
        siteName: siteName,
        name: name,
        status: status
      }, function (sdata) {
        loading.close();
        bt.msg(sdata);
      })
    },
    set_dirpath: function (web) {
      var loading = bt.load();
      bt.site.get_site_path(web.id, function (path) {
        bt.site.get_dir_userini(web.id, path, function (rdata) {
          loading.close();
          if (rdata.status == false) {
            bt.msg(rdata)
            return;
          }
          var dirs = [];
          for (var n = 0; n < rdata.runPath.dirs.length; n++) dirs.push({
            title: rdata.runPath.dirs[n],
            value: rdata.runPath.dirs[n]
          });
          var datas = [{
              title: '',
              items: [{
                  name: 'userini',
                  type: 'checkbox',
                  text: '防跨站攻击(open_basedir)<a href="https://www.bt.cn/bbs/thread-50988-1-1.html" target="_blank" class="bt-ico-ask">?</a>',
                  value: rdata.userini,
                  callback: function (sdata) {
                    bt.site.set_dir_userini(web.name, path, function (ret) {
                      if (ret.status) site.reload(2)
                    })
                  }
                },
                {
                  name: 'logs',
                  type: 'checkbox',
                  text: '写访问日志',
                  value: rdata.logs,
                  callback: function (sdata) {
                    bt.site.set_logs_status(web.id, function (ret) {
                      if (ret.status) site.reload(2)
                    })
                  }
                }
              ]
            },
            {
              title: '',
              items: [{
                  name: 'en_asp',
                  type: 'checkbox',
                  text: '禁用Asp',
                  value: rdata.asp,
                  callback: function (sdata) {
                    site.edit.set_en_script(web.name, 'asp', sdata.en_asp)
                  }
                },
                {
                  name: 'en_aspx',
                  type: 'checkbox',
                  text: '禁用Aspx',
                  value: rdata.aspx,
                  callback: function (sdata) {
                    site.edit.set_en_script(web.name, 'aspx', sdata.en_aspx)
                  }
                },
                {
                  name: 'en_php',
                  type: 'checkbox',
                  text: '禁用PHP',
                  value: rdata.php,
                  callback: function (sdata) {
                    site.edit.set_en_script(web.name, 'php', sdata.en_php)
                  }
                }
              ]
            },
            {
              name: 'config_lock',
              type: 'checkbox',
              text: '锁定配置文件(IIS部署Wordpress必选)<a href="https://www.bt.cn/bbs/thread-51149-1-1.html" target="_blank" class="bt-ico-ask">?</a>',
              value: rdata.locking,
              callback: function (sdata) {
                bt.site.set_config_locking(web.name, function (ret) {
                  if (ret.status) site.reload()
                  bt.msg(ret)
                })
              }
            },
            {
              title: '',
              items: [{
                  name: 'path',
                  title: '网站目录',
                  width: '50%',
                  value: path,
                  event: {
                    css: 'glyphicon-folder-open',
                    callback: function (obj) {
                      bt.select_path(obj);
                    }
                  }
                },
                {
                  name: 'btn_site_path',
                  type: 'button',
                  text: '保存',
                  callback: function (pdata) {
                    bt.site.set_site_path({id:web.id, path:pdata.path,check_dir:1}, function (ret) {
                      if (ret.status == false) {
                        bt.msg(ret);
                        return;
                      }
                      if (ret.status) site.reload()
                      bt.msg(ret);
                    })
                  }
                }
              ]
            },
            {
              title: '',
              items: [{
                  title: '运行目录',
                  width: '50%',
                  value: rdata.runPath.runPath,
                  name: 'dirName',
                  type: 'select',
                  items: dirs
                },
                {
                  name: 'btn_run_path',
                  type: 'button',
                  text: '保存',
                  callback: function (pdata) {
                    bt.site.set_site_runpath(web.id, pdata.dirName, function (ret) {
                      if (ret.status) site.reload()
                    })
                  }
                }
              ]
            }
          ]
          var _html = $("<div class='webedit-box soft-man-con'></div>")
          var clicks = [];
          for (var i = 0; i < datas.length; i++) {
            var _form_data = bt.render_form_line(datas[i]);
            _html.append($(_form_data.html).addClass('line mtb10'));
            clicks = clicks.concat(_form_data.clicks);
          }
          _html.find('input[type="checkbox"]').parent().addClass('label-input-group ptb10');
          _html.find('button[name="btn_run_path"]').addClass('ml45');
          _html.find('button[name="btn_site_path"]').addClass('ml33');
          _html.append(bt.render_help(['部分程序需要指定二级目录作为运行目录，如ThinkPHP5，Laravel', '选择您的运行目录，点保存即可', 'wordpress安装/修改模块导致网站500错误 <a style="color:#20a53a;" href="https://www.bt.cn/bbs/thread-33097-1-1.html" target="_blank">参考此贴</a>', '锁定配置将保护您的站点配置文件不被替换/修改等操作 <font style="color:red">(PS:可通过面板修改配置并校验格式正确性)</font>', '如锁定配置，需要手动删除网站目录的IIS_IUSRS权限']));
          if (bt.os == 'Linux') _html.append('<div class="user_pw_tit" style="margin-top: 2px;padding-top: 11px;"><span class="tit">密码访问</span><span class="btswitch-p"><input class="btswitch btswitch-ios" id="pathSafe" type="checkbox"><label class="btswitch-btn phpmyadmin-btn" for="pathSafe" ></label></span></div><div class="user_pw" style="margin-top: 10px; display: block;"></div>')

          $('#webedit-con').append(_html);
          bt.render_clicks(clicks);
          $('#pathSafe').click(function () {
            var val = $(this).prop('checked');
            var _div = $('.user_pw')
            if (val) {
              var dpwds = [{
                  title: '授权账号',
                  width: '200px',
                  name: 'username_get',
                  placeholder: '不修改请留空'
                },
                {
                  title: '访问密码',
                  width: '200px',
                  type: 'password',
                  name: 'password_get_1',
                  placeholder: '不修改请留空'
                },
                {
                  title: '重复密码',
                  width: '200px',
                  type: 'password',
                  name: 'password_get_2',
                  placeholder: '不修改请留空'
                },
                {
                  name: 'btn_password_get',
                  text: '保存',
                  type: 'button',
                  callback: function (rpwd) {
                    if (rpwd.password_get_1 != rpwd.password_get_2) {
                      layer.msg(lan.bt.pass_err_re, {
                        icon: 2
                      });
                      return;
                    }
                    bt.site.set_site_pwd(web.id, rpwd.username_get, rpwd.password_get_1, function (ret) {
                      if (ret.status) site.reload(2)
                    })
                  }
                }
              ]
              for (var i = 0; i < dpwds.length; i++) {
                var _from_pwd = bt.render_form_line(dpwds[i]);
                _div.append("<div class='line'>" + _from_pwd.html + "</div>");
                bt.render_clicks(_from_pwd.clicks);
              }
            } else {
              bt.site.close_site_pwd(web.id, function (rdata) {
                layer.msg(rdata.msg, {
                  icon: rdata.status ? 1 : 2
                });
                _div.html('');
              })
            }
          })
          if (rdata.pass) $('#pathSafe').trigger('click');
        })
      })
    },
    set_apppool: function (web, index) {
      if (index == undefined) index = 0;
      var loadT = bt.load();
      bt.site.get_net_version_byaspp(web.name, function (ndata) {
        loadT.close();
        if (ndata.status === false) {
          bt.msg(ndata);
          return;
        }

        bt.site.get_iis_net_versions(function (ldata) {
          if (ldata.status === false) {
            bt.msg(ldata);
            return;
          }

          $('#webedit-con').html("<div id='pool_tabs'></div><div class=\"tab-con\" style=\"padding:20px 0px;\"></div>");

          var _tabs = [{
              title: '基础设置',
              callback: function (robj) {
                var nets = [];
                for (var i = 0; i < ldata.length; i++) nets.push({
                  title: ldata[i],
                  value: ldata[i]
                })
                nets.push({
                  title: "无托管代码",
                  value: ""
                })

                var shtml = '<p  style="margin-left:30px;" class="status">当前状态：<span>开启</span><span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play"></span>'
                var opttxt = '停止'
                if (ndata.status != 'Started') {
                  shtml = '<p class="status">当前状态：<span>关闭</span><span style="color: red; margin-left: 3px;" class="glyphicon glyphicon-pause"></span>'
                  opttxt = '启动'
                }
                shtml += '<span class="app_status" style="margin-left:20px;"><button class="btn btn-default btn-sm">' + opttxt + '</button> <button class="btn btn-default btn-sm">重启</button></span></p>'

                var _html = $('<div class="webedit-box soft-man-con"> ' + shtml + ' </div>')

                var datas = [{
                    title: '托管管道模式',
                    name: 'model',
                    type: 'select',
                    value: ndata.type,
                    items: [{
                      title: '集成',
                      value: 'Integrated'
                    }, {
                      title: '经典',
                      value: 'Classic'
                    }]
                  },
                  {
                    title: '.NET 版本',
                    name: 'net_version',
                    type: 'select',
                    value: ndata.version,
                    items: nets
                  },
                  {
                    title: '32位应用程序',
                    name: 'enable32BitAppOnWin64',
                    type: 'select',
                    value: ndata.enable32BitAppOnWin64,
                    ps: 'x64系统下仍加载x86应用程序池，默认开启',
                    items: [{
                      title: '启用',
                      value: 'true'
                    }, {
                      title: '停用',
                      value: 'false'
                    }]
                  },
                  {
                    title: '队列长度',
                    name: 'queueLength',
                    width: "130px",
                    type: 'number',
                    value: ndata.queueLength,
                    ps: '默认10000，超过此长度将响应503'
                  },
                  {
                    title: '  ',
                    name: 'btn_set_app',
                    text: '保存',
                    type: 'button',
                    callback: function (ldata) {
                      ldata['name'] = web.name;
                      bt.site.set_iis_apppool(ldata, function (ret) {
                        if (ret.status) site.edit.set_apppool(web, 0)
                      })
                    }
                  }
                ]
                robj.append(_html);
                for (var i = 0; i < datas.length; i++) {
                  bt.render_form_line(datas[i], '', robj);
                }
                robj.append(bt.render_help(['注意：如果Aspx网站出现404，请使用在命令行输入以下命令启用Aspx.net', '  C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regiis.exe -i', ' C:\\WINDOWS\\Microsoft.NET\\Framework\\v4.0.30319\\aspnet_regiis.exe -i', 'IIS性能调整与异常排除<a href="https://www.bt.cn/bbs/thread-33111-1-1.html" target="_blank" class="btlink"> 使用帮助</a>']))

                $(".app_status button").click(function () {
                  var _index = $(this).index();
                  var opt = "start";
                  if (ndata.status == 'Started') opt = "stop";
                  if (_index == 1) opt = "restart";
                  var msg = lan.bt[opt];
                  bt.confirm({
                    msg: "是否确定" + msg + "程序池[" + web.name + "]？",
                    title: '提示'
                  }, function () {
                    bt.site.set_apppool_status(web.name, opt, function (ret) {
                      if (ret.status) {
                        site.get_class_type();
                        site.edit.set_apppool(web, 0)
                      }
                      bt.msg(ret);
                    })
                  })
                })
              }
            },
            {
              title: '回收设置',
              callback: function (robj) {
                var periodicRestart = ndata.periodicRestart;
                var re_data = [{
                    title: '内存限制',
                    name: 'privateMemory',
                    width: "120px",
                    type: 'number',
                    value: periodicRestart.privateMemory,
                    unit: 'KB'
                  },
                  {
                    title: '请求限制',
                    name: 'requests',
                    width: "120px",
                    type: 'number',
                    value: periodicRestart.requests
                  },
                  {
                    title: '固定回收时间',
                    name: 'time',
                    width: "180px",
                    type: 'number',
                    value: periodicRestart.time,
                    unit: '秒'
                  },
                  {
                    title: ' ',
                    items: [{
                        title: '  ',
                        name: 'btn_site_app_recycling',
                        text: '应用本站',
                        type: 'button',
                        callback: function (ldata) {
                          ldata['is_global'] = 0;
                          site.edit.set_site_app_recycling(web, ldata)
                        }
                      },
                      {
                        title: '  ',
                        name: 'btn_all_app_recycling',
                        text: '应用所有',
                        type: 'button',
                        callback: function (ldata) {
                          ldata['is_global'] = 0;
                          site.edit.set_site_app_recycling(web, ldata)
                        }
                      },
                    ]
                  }
                ]
                for (var i = 0; i < re_data.length; i++) {
                  bt.render_form_line(re_data[i], '', robj)
                }
                $(".btn_all_app_recycling").removeClass('btn-success').addClass('btn-danger');

                robj.append('<div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px;margin-top: 20px;"> <input id="recycling_time" class="bt-input-text recycling_time" style="width:280px"  type="text" value=""  placeholder="每天定时回收程序池,格式：12:00"><button class="btn btn_add_recycling btn-success btn-sm va0 mlr15" >添加</button></div><div class="divtable" style="max-height:150px;overflow:auto;border:#ddd 1px solid"><table id="pool_recycling_list" class="table table-hover" style="border:none;"></table></div>');

                var schedule_list = []
                for (var i = 0; i < periodicRestart.schedule.length; i++) schedule_list.push({
                  time_start: periodicRestart.schedule[i]
                })

                bt.render({
                  table: '#pool_recycling_list',
                  columns: [{
                      field: 'time_start',
                      title: '时间（24小时制）'
                    },
                    {
                      field: 'opt',
                      width: '70px',
                      title: '操作',
                      templet: function (item) {
                        return '<a class="btlink pool_recycling_del">删除</a>'
                      }
                    }
                  ],
                  data: schedule_list
                });

                robj.append(bt.render_help(['内存限制：超过内存限制自动回收，0表示不限制', '请求限制：超过请求限制自动回收,0表示不限制', '固定回收时间：固定回收，默认1740分钟', '定时回收：表示每天固定时间回收程序池，建议设置在半夜。', 'IIS性能调整与异常排除<a href="https://www.bt.cn/bbs/thread-33111-1-1.html" target="_blank" class="btlink"> 使用帮助</a>']))


                $(".pool_recycling_del").click(function () {
                  var item = $(this).parents('tr').data('item')
                  site.edit.set_site_recycling_bytime(web, item.time_start, "0");
                })

                $(".btn_add_recycling").click(function () {
                  site.edit.set_site_recycling_bytime(web, $(".recycling_time").val() + ':00', "1");
                })

                //时间选择器
                laydate.render({
                  elem: '#recycling_time',
                  type: 'time',
                  trigger: 'click',
                  theme: '#20a53a',
                  format: 'HH:mm'
                });
              }
            },
            {
              title: '故障防护',
              callback: function (robj) {
                var failure = ndata.failure;
                var failure_data = [{
                    title: '状态',
                    name: 'rapidFailProtection',
                    width: "120px",
                    type: 'select',
                    value: failure.rapidFailProtection,
                    items: [{
                      title: '开启',
                      value: 'true'
                    }, {
                      title: '关闭',
                      value: 'false'
                    }]
                  },
                  {
                    title: '故障间隔',
                    name: 'rapidFailProtectionInterval',
                    width: "120px",
                    type: 'number',
                    value: failure.rapidFailProtectionInterval,
                    unit: '分钟'
                  },
                  {
                    title: '最大故障次数',
                    name: 'rapidFailProtectionMaxCrashes',
                    width: "120px",
                    type: 'number',
                    value: failure.rapidFailProtectionMaxCrashes,
                    unit: '次'
                  },
                  {
                    title: '故障处理方式',
                    name: 'failure_type',
                    width: "150px",
                    type: 'select',
                    value: failure.failure_type,
                    items: [{
                      title: '不处理',
                      value: 'false'
                    }, {
                      title: '重启当前程序池',
                      value: 'start_pool'
                    }, {
                      title: '重启IIS',
                      value: 'restart_iis'
                    }]
                  },
                  {
                    title: ' ',
                    items: [{
                        title: '  ',
                        name: 'btn_site_app_failure',
                        text: '应用本站',
                        type: 'button',
                        callback: function (ldata) {
                          ldata['is_global'] = 0;

                          site.edit.set_site_app_failure(web, ldata)
                        }
                      },
                      {
                        title: '  ',
                        name: 'btn_all_app_failure',
                        text: '应用所有',
                        type: 'button',
                        callback: function (ldata) {
                          ldata['is_global'] = 1;
                          site.edit.set_site_app_failure(web, ldata)
                        }
                      },
                    ]
                  }
                ]
                for (var i = 0; i < failure_data.length; i++) {
                  bt.render_form_line(failure_data[i], '', robj)
                }
                $(".btn_all_app_failure").removeClass('btn-success').addClass('btn-danger');

                robj.append(bt.render_help(['【故障间隔】内发送了【最大故障次数】错误则停止程序池，整站响应503错误', '故障处理方式：当应用程序池被异常关闭后触发的处理方式.', 'IIS性能调整与异常排除<a href="https://www.bt.cn/bbs/thread-33111-1-1.html" target="_blank" class="btlink"> 使用帮助</a>']))
              }
            },
            {
              title: '工作进程',
              callback: function (robj) {
                var process = ndata.processModel;
                var re_data = [{
                    title: '最大工作进程',
                    name: 'maxProcesses',
                    width: "180px",
                    type: 'number',
                    value: process.maxProcesses
                  },
                  {
                    title: '启动超时',
                    name: 'startupTimeLimit',
                    width: "180px",
                    type: 'number',
                    value: process.startupTimeLimit,
                    unit: ' 秒'
                  },
                  {
                    title: '请求超时',
                    name: 'shutdownTimeLimit',
                    width: "180px",
                    type: 'number',
                    value: process.shutdownTimeLimit,
                    unit: ' 秒'
                  },
                  {
                    title: '闲置超时',
                    name: 'idleTimeout',
                    width: "180px",
                    type: 'number',
                    value: process.idleTimeout,
                    unit: ' 秒'
                  },
                  {
                    title: ' ',
                    items: [{
                      title: '  ',
                      name: 'btn_site_app_process',
                      text: '保存',
                      type: 'button',
                      callback: function (ldata) {
                        site.edit.set_site_app_process(web, ldata)
                      }
                    }]
                  }
                ]

                for (var i = 0; i < re_data.length; i++) {
                  bt.render_form_line(re_data[i], '', robj)
                }
                robj.append(bt.render_help(['启动超时：启动程序池超时时间', '请求超时：完成处理请求超时时间', '闲置超时：超过此时间未收到请求，此进程将进入闲置状态', '最大工作进程：应用池启动进程数,增加进程数可有效缓解进程池压力(<span style="color:red">注意：每增加一个进程将会增加200M内存占用，并且可能会造成用户登录状态丢失，谨慎使用。</span>)', 'IIS性能调整与异常排除<a href="https://www.bt.cn/bbs/thread-33111-1-1.html" target="_blank" class="btlink"> 使用帮助</a>']))
              }
            },
            {
              title: '活动进程',
              callback: function (robj) {

                var loading = bt.load();
                bt.send('get_iis_process_list', 'site/get_iis_process_list', {
                  siteName: web.name
                }, function (rdata) {
                  loading.close();

                  if (rdata.status === false) {
                    bt.msg(rdata);
                    return;
                  }
                  var _total_html = ' <table class="table table-hover table-bordered" style="width: 490px;margin-bottom:10px;background-color:#fafafa">\
					                        <tbody> <tr><th style="width:80px">总连接数：</th><td>' + rdata.total_request + '</td><th style="width:80px">总内存：</th><td>' + rdata.total_memory + ' KB</td><th style="width:80px">总CPU：</th><td>' + rdata.total_cpu + ' %</td></tr></tbody>\
					                    </table>'
                  var con = "<div class='divtable style='padding-bottom: 0'><table width='100%' id='tab_iis_status' class='table table-hover'></table></div>";
                  robj.html(_total_html + con);

                  var _tab = bt.render({
                    table: '#tab_iis_status',
                    columns: [{
                        field: 'name',
                        title: '网站名',
                        width: "100px"
                      },
                      {
                        field: 'pid',
                        title: '进程ID',
                        width: "100px"
                      },
                      {
                        field: 'cpu',
                        title: 'CPU',
                        width: "100px"
                      },
                      {
                        field: 'memory',
                        title: '内存(KB)',
                        width: "100px"
                      },
                      {
                        field: 'request',
                        title: '活动连接数',
                        width: "100px"
                      },
                      {
                        field: 'opt',
                        title: '操作',
                        width: "100px",
                        templet: function (item) {
                          return '<a class="btlink get_request_info">查看</a>'
                        }
                      }
                    ],
                    data: rdata.apps
                  })
                  $(".get_request_info").click(function () {
                    var _item = $(this).parents('tr').data('item')

                    bt.soft.web.get_iis_request_list(_item.pid, function (res) {
                      if ($("#iis_request_list").length <= 0) {
                        bt.open({
                          type: 1,
                          title: "[" + _item.name + "]活动进程",
                          area: ['500px', '500px'],
                          closeBtn: 2,
                          shadeClose: false,
                          content: '<div class="pd15 div_cn_form"><div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px"></div><div class="divtable" style="max-height:300px;overflow:auto;border:#ddd 1px solid"><table id="iis_request_list" class="table table-hover gztr" style="border:none;"></table></div></div>',
                          success: function () {
                            init_request_data_list(res);
                          }
                        })
                      } else {
                        init_request_data_list(res)
                      }

                      function init_request_data_list(res) {
                        var _tab = bt.render({
                          table: '#iis_request_list',
                          columns: [{
                              field: 'method',
                              title: '类型',
                              width: "100px"
                            },
                            {
                              field: 'url',
                              title: 'URL',
                              width: "100px"
                            },
                            {
                              field: 'time',
                              title: '耗时',
                              width: "100px"
                            },
                            {
                              field: 'client',
                              title: '客户端',
                              width: "100px"
                            },
                            {
                              field: 'module',
                              title: '处理模块',
                              width: "100px"
                            },

                          ],
                          data: res
                        })
                      }
                    })
                  })
                })


              }
            }
          ]
          bt.render_tab('pool_tabs', _tabs);
          $('#pool_tabs span:eq(' + index + ')').trigger('click');
        })
      })
    },
    set_site_app_process: function (web, ldata) {
      ldata['siteName'] = web.name
      var loading = bt.load();
      bt.send('set_site_app_process', 'site/set_site_app_process', ldata, function (rRet) {
        loading.close();
        if (rRet.status) {
          site.edit.set_apppool(web, 3)
        }
        bt.msg(rRet);
      })
    },
    set_site_recycling_bytime: function (web, recycling_time, stype) {

      var loading = bt.load();
      bt.send('set_site_recycling_bytime', 'site/set_site_recycling_bytime', {
        siteName: web.name,
        recycling_time: recycling_time,
        stype: stype
      }, function (rRet) {
        loading.close();
        if (rRet.status) {
          site.edit.set_apppool(web, 1)
        }
        bt.msg(rRet);
      })
    },
    set_site_app_recycling: function (web, ldata) {
      ldata['siteName'] = web.name
      var loading = bt.load();
      bt.send('set_iis_app_recycling', 'site/set_iis_app_recycling', ldata, function (rRet) {
        loading.close();
        if (rRet.status) {
          site.edit.set_apppool(web, 1)
        }
        bt.msg(rRet);
      })
    },
    set_site_app_failure: function (web, ldata) {
      ldata['siteName'] = web.name
      var loading = bt.load();
      bt.send('set_iis_app_failure', 'site/set_iis_app_failure', ldata, function (rRet) {
        loading.close();
        if (rRet.status) {
          site.edit.set_apppool(web, 2)
        }
        bt.msg(rRet);
      })
    },
    set_error_page: function (web) {
      bt.site.get_site_error_pages(web.name, function (rdata) {
        if (rdata.status === false) {
          bt.msg(rdata);
          return;
        }
        var _from_data = {
          items: [{
              title: '响应错误模式：',
              width: '330px',
              name: 'error_model',
              type: 'select',
              value: rdata.error_model,
              items: [{
                title: '自定义错误页',
                value: 'Custom'
              }, {
                title: '详细错误页',
                value: 'Detailed'
              }, {
                title: '本地请求的详细错误页和远程请求的自定义错误页',
                value: 'DetailedLocalOnly'
              }]
            },
            {
              name: 'btn_set_error_model',
              text: '切换',
              type: 'button',
              callback: function (ldata) {
                ldata['name'] = web.name;
                bt.site.set_site_error_model(ldata, function (ret) {
                  if (ret.status) {
                    site.reload()
                  }
                  bt.msg(ret);
                })
              }
            }
          ]
        }
        bt.render_form_line(_from_data, '', $("#webedit-con").empty());

        $('#webedit-con').append("<div class='divtable mtb15' style='height:380px;overflow:auto'><table id='error_page_table' class='table table-hover' width='100%'></table></div>");
        bt.render({
          table: '#error_page_table',
          columns: [{
              field: 'statusCode',
              width: '55px',
              title: '错误码',
              templet: function (item) {
                return item.statusCode
              }
            },
            {
              field: 'responseMode',
              width: '60px',
              title: '类型',
              templet: function (item) {
                switch (item.responseMode) {
                  case 'File':
                    return "文件";
                  case "ExecuteURL":
                    return "根目录";
                    break;
                  case "Redirect":
                    return "重定向";
                    break;
                }
              }
            },
            {
              field: 'path',
              title: '路径',
              templet: function (item) {

                if (item.prefixLanguageFilePath != "") {
                  var path = item.prefixLanguageFilePath + '\\' + item.path;
                  return path;
                } else {
                  return item.path;
                }
              }
            },
            {
              field: 'opt',
              width: '80px',
              title: '操作',
              templet: function (item) {
                return '<a class="btlink edit_error_page" href="javascript:;">编辑</a> | <a class="btlink re_error_page" href="javascript:;">还原</a>';
              }
            }
          ],
          data: rdata.list
        })
        $(".re_error_page").click(function () {
          var item = $(this).parents('tr').data('item')
          bt.confirm({
            msg: "是否确定还原错误码[" + item.statusCode + "]显示页？",
            title: '提示'
          }, function () {
            bt.site.re_error_page_bycode(web.name, item.statusCode, function (ret) {
              if (ret.status) {
                site.reload()
              }
              bt.msg(ret);
            })
          })
        })

        $(".edit_error_page").click(function () {
          var item = $(this).parents('tr').data('item')
          bt.render_form({
            title: "编辑【" + item.statusCode + "】错误页",
            area: '530px',
            list: [{
                title: '错误码',
                name: 'code',
                value: item.statusCode,
                disabled: true
              },
              {
                title: '类型',
                name: 'responseMode',
                type: 'select',
                value: item.responseMode,
                items: [{
                  title: '根目录',
                  value: 'ExecuteURL'
                }, {
                  title: '重定向',
                  value: 'Redirect'
                }]
              },
              {
                title: '地址',
                name: 'path',
                value: item.path
              }
            ],
            btns: [{
                title: '关闭',
                name: 'close'
              },
              {
                title: '提交',
                name: 'submit',
                css: 'btn-success',
                callback: function (rdata, load, callback) {
                  if (rdata.responseMode == 'Redirect') {
                    if (!bt.check_url(rdata.path)) {
                      bt.msg({
                        icon: 2,
                        msg: '地址格式不正确,格式为：https://www.bt.cn'
                      });
                      return;
                    }
                  } else {
                    var reg = /^\/.+/;
                    if (!reg.test(rdata.path)) {
                      bt.msg({
                        icon: 2,
                        msg: '地址格式不正确,格式为：/404.html'
                      });
                      return;
                    }
                  }
                  bt.confirm({
                    msg: "您确定修改" + item.statusCode + "错误页吗？",
                    title: "编辑"
                  }, function () {
                    var loading = bt.load();
                    rdata['name'] = web.name;
                    bt.send('set_error_page_bycode', 'site/set_error_page_bycode', rdata, function (rRet) {
                      loading.close();
                      if (rRet.status) {
                        load.close();
                        site.reload()
                      }
                      bt.msg(rRet);
                    })
                  })
                }
              }
            ]
          })
        })
        $('#webedit-con').append(bt.render_help(['重定向：302重定向到指定url(如：https://www.bt.cn)', '根目录：访问到网站根目录指定文件(如：/404.html)', 'IIS出现500错误处理方案 <a href="https://www.bt.cn/bbs/thread-33102-1-1.html" target="_blank" class="btlink"> 使用帮助</a>']));
      })
    },
    set_dirguard: function (web) {
      String.prototype.myReplace = function (f, e) { //吧f替换成e
        var reg = new RegExp(f, "g"); //创建正则RegExp对象
        return this.replace(reg, e);
      }
      bt.site.get_dir_auth(web.id, function (res) {
        if (res.status == false) {
          bt.msg(res)
          return;
        }
        var datas = {
          items: [{
            name: 'add_dir_guard',
            text: '添加目录保护',
            type: 'button',
            callback: function (data) {
              site.edit.template_Dir(web.id, true)
            }
          }]
        }
        var form_line = bt.render_form_line(datas);
        $('#webedit-con').append(form_line.html);
        bt.render_clicks(form_line.clicks);
        $('#webedit-con').addClass('divtable').append('<table id="dir_guard" class="table table-hover"></table>');
        setTimeout(function () {
          var data = [];
          var _tab = bt.render({
            table: '#dir_guard',
            columns: [{
                field: 'name',
                title: '名称',
                template: function (item) {
                  return '<span style="width:60px;" title="' + item.name + '">' + item.name + '</span>'
                }
              },
              {
                field: 'site_dir',
                title: '保护的目录',
                template: function (item) {
                  return '<span style="width:60px;" title="' + item.site_dir + '">' + item.site_dir + '</span>'
                }
              },
              {
                field: 'dname',
                title: '操作',
                align: 'right',
                templet: function (item) {
                  var dirName = item.name
                  item = JSON.stringify(item).myReplace('"', '\'');
                  var conter = '<a class="btlink" onclick="site.edit.template_Dir(\'' + web.id + '\',false,' + item + ')" href="javascript:;">编辑</a> ' +
                    '| <a class="btlink" onclick="bt.site.delete_dir_guard(\'' + web.id + '\',\'' + dirName + '\',function(rdata){if(rdata.status)site.reload()})" href="javascript:;">删除</a>';
                  return conter
                }
              }
            ],
            data: res
          })

        })
      });
    },

    limit_network: function (web) {
      var loadT = bt.load();
      bt.site.get_limitnet(web.id, function (rdata) {
        loadT.close();
        if (rdata.status === false) {
          bt.msg(rdata);
          return;
        }
        var limits = [{
            title: '论坛/博客',
            value: 1,
            items: {
              perserver: 300,
              perip: 25,
              limit_rate: 512
            }
          },
          {
            title: '图片站',
            value: 2,
            items: {
              perserver: 200,
              perip: 10,
              limit_rate: 1024
            }
          },
          {
            title: '下载站',
            value: 3,
            items: {
              perserver: 50,
              perip: 3,
              limit_rate: 2048
            }
          },
          {
            title: '商城',
            value: 4,
            items: {
              perserver: 500,
              perip: 10,
              limit_rate: 2048
            }
          },
          {
            title: '门户',
            value: 5,
            items: {
              perserver: 400,
              perip: 15,
              limit_rate: 1024
            }
          },
          {
            title: '企业',
            value: 6,
            items: {
              perserver: 60,
              perip: 10,
              limit_rate: 512
            }
          },
          {
            title: '视频',
            value: 7,
            items: {
              perserver: 150,
              perip: 4,
              limit_rate: 1024
            }
          }
        ]
        var datas = [{
            items: [{
              name: 'status',
              type: 'checkbox',
              value: rdata.perserver != 0 ? true : false,
              text: '启用流量控制',
              callback: function (ldata) {
                if (ldata.status) {
                  bt.site.set_limitnet(web.id, ldata, function (ret) {
                    if (ret.status) site.reload(3)
                  })
                } else {
                  bt.site.close_limitnet(web.id, function (ret) {
                    if (ret.status) site.reload(3)
                  })
                }
              }
            }]
          },
          {
            items: [{
              title: '限制方案  ',
              width: '160px',
              name: 'limit',
              type: 'select',
              items: limits,
              callback: function (obj) {
                var data = limits.filter(function (p) {
                  return p.value === parseInt(obj.val());
                })[0]
                for (var key in data.items) $('input[name="' + key + '"]').val(data.items[key]);
              }
            }]
          },
          {
            items: [{
              title: '并发限制   ',
              type: 'number',
              width: '200px',
              value: rdata.perserver,
              name: 'perserver'
            }]
          },
          {
            hide: bt.os == 'Linux' ? false : true,
            items: [{
              title: '单IP限制   ',
              type: 'number',
              width: '200px',
              value: rdata.perip,
              name: 'perip'
            }]
          },
          {
            hide: bt.os == 'Linux' ? true : false,
            items: [{
              title: '超时时间   ',
              type: 'number',
              width: '200px',
              value: rdata.timeout ? rdata.timeout : 120,
              name: 'timeout'
            }]
          },
          {
            items: [{
              title: '流量限制   ',
              type: 'number',
              width: '200px',
              value: rdata.limit_rate,
              name: 'limit_rate'
            }]
          },
          {
            name: 'btn_limit_get',
            text: '保存',
            type: 'button',
            callback: function (ldata) {
              bt.site.set_limitnet(web.id, ldata, function (ret) {
                if (ret.status) site.reload(3)
              })
            }
          }
        ]
        var _html = $("<div class='webedit-box soft-man-con'></div>")
        var clicks = [];
        for (var i = 0; i < datas.length; i++) {
          var _form_data = bt.render_form_line(datas[i]);
          _html.append(_form_data.html);
          clicks = clicks.concat(_form_data.clicks);
        }
        _html.find('input[type="checkbox"]').parent().addClass('label-input-group ptb10');
        _html.append(bt.render_help(['限制当前站点最大并发数', '限制单个IP访问最大并发数', '限制每个请求的流量上限（单位：KB）']));
        $('#webedit-con').append(_html);
        bt.render_clicks(clicks);
        if (rdata.perserver == 0) $("select[name='limit']").trigger("change")
      })
    },
    get_rewrite_list: function (web) {
      var filename = '/www/server/panel/vhost/rewrite/' + web.name + '.conf';
      if (bt.get_cookie('serverType') == 'apache') filename = web.path + '/.htaccess';
      bt.site.get_rewrite_list(web.name, function (rdata) {
        var arrs = [];
        for (var i = 0; i < rdata.rewrite.length; i++) arrs.push({
          title: rdata.rewrite[i],
          value: rdata.rewrite[i]
        });

        var datas = [{
            name: 'rewrite',
            type: 'select',
            width: '130px',
            items: arrs,
            callback: function (obj) {
              var spath = filename;
              if (bt.os != 'Linux' && obj.val() == lan.site.rewritename) {
                var loadT = bt.load()
                bt.site.get_site_rewrite(web.name, function (ret) {
                  if (ret.status === false) {
                    bt.msg(ret);
                    return;
                  }
                  loadT.close()
                  editor.setValue(ret.data);
                })
              } else {
                if (obj.val() != lan.site.rewritename) spath = setup_path + '/panel/rewrite/' + bt.get_cookie('serverType') + '/' + obj.val() + '.conf';
                bt.files.get_file_body(spath, function (ret) {
                  editor.setValue(ret.data);
                })
              }
            }
          },
          {
            items: [{
              name: 'config',
              type: 'textarea',
              value: rdata.data,
              widht: '340px',
              height: '200px'
            }]
          },
          {
            items: [{
                name: 'btn_save',
                text: '保存',
                type: 'button',
                callback: function (ldata) {
                  if (bt.os == "Linux") {
                    bt.files.set_file_body(filename, editor.getValue(), 'utf-8', function (ret) {
                      if (ret.status) site.reload(4)
                      bt.msg(ret);
                    })
                  } else {
                    var loading = bt.load();
                    bt.site.set_site_rewrite(web.name, editor.getValue(), function (ret) {
                      loading.close()
                      if (ret.status) site.reload()
                      bt.msg(ret);
                    })
                  }
                }
              },
              {
                name: 'btn_save_to',
                text: '另存为模板',
                type: 'button',
                callback: function (ldata) {
                  var temps = {
                    title: lan.site.save_rewrite_temp,
                    area: '330px',
                    list: [{
                      title: '模板名称',
                      placeholder: '模板名称',
                      width: '160px',
                      name: 'tempname'
                    }],
                    btns: [{
                        title: '关闭',
                        name: 'close'
                      },
                      {
                        title: '提交',
                        name: 'submit',
                        css: 'btn-success',
                        callback: function (rdata, load, callback) {
                          bt.site.set_rewrite_tel(rdata.tempname, editor.getValue(), function (rRet) {
                            if (rRet.status) {
                              load.close();
                              site.reload(4)
                            }
                            bt.msg(rRet);
                          })
                        }
                      }
                    ]
                  }
                  bt.render_form(temps);
                }
              }
            ]
          }
        ]
        var _html = $("<div class='webedit-box soft-man-con'></div>")
        var clicks = [];
        for (var i = 0; i < datas.length; i++) {
          var _form_data = bt.render_form_line(datas[i]);
          _html.append(_form_data.html);
          var _other = (bt.os == 'Linux' && i == 0) ? '<span>规则转换工具：<a href="https://www.bt.cn/Tools" target="_blank" style="color:#20a53a">Apache转Nginx</a></span>' : '';
          _html.find('.info-r').append(_other)
          clicks = clicks.concat(_form_data.clicks);
        }
        _html.append(bt.render_help(['请选择您的应用，若设置伪静态后，网站无法正常访问，请尝试设置回default', '您可以对伪静态规则进行修改，修改完后保存即可。']));
        $('#webedit-con').append(_html);
        bt.render_clicks(clicks);

        $('textarea.config').attr('id', 'config_rewrite');
        var editor = CodeMirror.fromTextArea(document.getElementById("config_rewrite"), {
          extraKeys: {
            "Ctrl-Space": "autocomplete"
          },
          lineNumbers: true,
          matchBrackets: true,
        });
        $(".CodeMirror-scroll").css({
          "height": "340px",
          "margin": 0,
          "padding": 0
        });
        $('select.rewrite').trigger('change')

      })
    },
    set_default_index: function (web) {
      var loadT = bt.load();
      bt.site.get_index(web.id, function (rdata) {
        loadT.close();
        if (rdata.status === false) {
          bt.msg(rdata);
          return;
        }
        rdata = rdata.replace(new RegExp(/(,)/g), "\n");
        var data = {
          items: [{
              name: 'Dindex',
              height: '230px',
              width: '50%',
              type: 'textarea',
              value: rdata
            },
            {
              name: 'btn_submit',
              text: '保存',
              type: 'button',
              callback: function (ddata) {
                var Dindex = ddata.Dindex.replace(new RegExp(/(\n)/g), ",");
                bt.site.set_index(web.id, Dindex, function (ret) {
                  if (ret.status) site.reload(5)
                })
              }
            }
          ]
        }
        var _form_data = bt.render_form_line(data);
        var _html = $(_form_data.html)
        _html.append(bt.render_help([lan.site.default_doc_help]))
        $('#webedit-con').append(_html);
        $('.btn_submit').addClass('pull-right').css("margin", "90px 100px 0 0")
        bt.render_clicks(_form_data.clicks);
      })
    },
    set_config: function (web) {
      var loadT = bt.load();
      bt.site.get_site_config(web.name, function (rdata) {
        loadT.close();
        if (rdata.status == false) {
          bt.msg(rdata);
          return;
        }
        var datas = [{
            items: [{
              name: 'site_config',
              type: 'textarea',
              value: rdata.data,
              widht: '340px',
              height: '200px'
            }]
          },
          {
            items: [{
                name: 'btn_config_submit',
                text: '保存',
                type: 'button',
                callback: function (ddata) {

                  bt.confirm({
                    msg: "修改默认配置可能会导致网站500错误，如不了解配置文件格式请勿随意修改，是否继续修改？",
                    title: '警告'
                  }, function () {
                    bt.site.set_site_config(web.name, editor.getValue(), rdata.encoding, function (ret) {
                      if (ret.status) site.reload(6)
                      bt.msg(ret);
                    })
                  })
                }
              },
              {
                name: 'btn_re_config_submit',
                text: '恢复默认配置',
                type: 'button',
                callback: function (ddata) {

                  bt.confirm({
                    msg: "网站配置将会恢复到初始状态，是否继续修改？",
                    title: '提示'
                  }, function () {
                    bt.site.set_re_site_config(web.name, function (ret) {
                      if (ret.status) site.reload(6)
                      bt.msg(ret);
                    })
                  })
                }
              }
            ]
          }
        ]
        var robj = $('#webedit-con');
        for (var i = 0; i < datas.length; i++) {
          var _form_data = bt.render_form_line(datas[i]);
          robj.append(_form_data.html);
          bt.render_clicks(_form_data.clicks);
        }
        var helps = [lan.site.web_config_help]
        if (bt.get_cookie('serverType') == 'iis') {
          helps.push('<span style="color:red">如您的部分操作不生效，请尝试将配置文件恢复到默认配置(如php版本，重定向等)</span>');
          helps.push('IIS配置文件格式说明 <a href="https://www.bt.cn/bbs/thread-33097-1-1.html" target="_blank" class="btlink"> 使用帮助</a>')
        }
        robj.append(bt.render_help(helps));
        $('textarea.site_config').attr('id', 'configBody');
        var editor = CodeMirror.fromTextArea(document.getElementById("configBody"), {
          extraKeys: {
            "Ctrl-Space": "autocomplete"
          },
          lineNumbers: true,
          matchBrackets: true,
        });
        $(".CodeMirror-scroll").css({
          "height": "400px",
          "margin": 0,
          "padding": 0
        });
      })
    },
    set_ssl: function (web) {
      var that = this;
      $('#webedit-con').html("<div id='ssl_tabs'></div><div class=\"tab-con\" style=\"padding:20px 0px;\"></div>");
      bt.site.get_site_ssl(web.name, function (rdata) {
        var _tabs = [{
            title: "商用证书<i class='ssl_recom_icon'></i>",
            callback: function (robj) {
              bt.pub.get_user_info(function (udata) {
                if (udata.status) {
                  var deploy_ssl_info = rdata,
                    html = '',
                    product_list, userInfo, order_list, is_check = true,
                    itemData, activeData, loadY, pay_ssl_layer;
                  bt.send('get_order_list', 'ssl/get_order_list', {}, function (rdata) {
                    order_list = rdata;
                    if (rdata.length == 0) {
                      $('#ssl_order_list tbody').html('<tr><td colspan="5" style="text-align:center;">暂无证书 <a class="btlink" href="javascript:$(\'.ssl_business_application\').click();"> ->申请证书</a></td></tr>');
                      return;
                    }
                    $.each(rdata, function (index, item) {
                      if (deploy_ssl_info.type == 3 && deploy_ssl_info.oid === item.oid) {
                        html += '<tr data-index="' + index + '">' +
                          '<td><span>' + item.domainName.join('、') + '</span></td><td>' + item.title + '</td><td>' + (function () {
                            var dayTime = new Date().getTime() / 1000,
                              color = '',
                              endTiems = '';
                            if (item.endDate != '') {
                              item.endDate = parseInt(item.endDate);
                              endTiems = parseInt((item.endDate - dayTime) / 86400);
                              if (endTiems <= 15) color = 'orange';
                              if (endTiems <= 7) color = 'red';
                              if (endTiems < 0) return '<span style="color:red">已过期</span>';
                              return '<span style="' + color + '">剩余' + endTiems + '天</span>';
                            } else {
                              return '--';
                            }
                          }()) +
                          '</td><td>订单完成</td><td style="text-align:right">已部署 | <a class="btlink" href="javascript:site.ssl.set_ssl_status(\'CloseSSLConf\',\'' + web.name + '\',2)">关闭</a></td></td>';
                      } else if (deploy_ssl_info.type != 3) {
                        html += '<tr data-index="' + index + '">' +
                          '<td><span>' + (item.domainName == null ? '--' : item.domainName.join('、')) + '</span></td><td>' + item.title + '</td><td>' + (function () {
                            var dayTime = new Date().getTime() / 1000,
                              color = '',
                              endTiems = '';
                            if (item.endDate != '') {
                              item.endDate = parseInt(item.endDate);
                              endTiems = parseInt((item.endDate - dayTime) / 86400);
                              if (endTiems <= 15) color = 'orange';
                              if (endTiems <= 7) color = 'red';
                              if (endTiems < 0) return '<span style="color:red">已过期</span>';
                              return '<span style="' + color + '">剩余' + endTiems + '天</span>'
                            } else {
                              return '--';
                            }
                          }()) +
                          '</td><td>' + (function () {
                            if (item.certId == '') {
                              return '<span style="color:orange;">待完善资料</span>';
                            } else if (item.status === 1) {
                              switch (item.orderStatus) {
                                case 'COMPLETE':
                                  return '<span style="color:#20a53a;">订单完成</span>';
                                  break;
                                case 'PENDING':
                                  return '<span style="color: orange;">申请中</span>';
                                  break;
                                case 'CANCELLED':
                                  return '<span style="color: #888;">已取消</span>';
                                  break;
                                case 'FAILED':
                                  return '<span style="color:red;">申请失败</span>';
                                  break;
                                default:
                                  return '<span style="color: orange;">待验证</span>';
                                  break;
                              }
                            } else {
                              switch (item.status) {
                                case 0:
                                  return '<span style="color: orange;">未支付</span>';
                                  break;
                                case -1:
                                  return '<span style="color: #888;">已取消</span>'
                                  break;
                              }
                            }
                          }()) +
                          '</td><td style="text-align:right;">' + (function () {
                            if (item.certId == '') {
                              var html = '';
                              if (item.install) html += '<a href="' + item.qq + '" class="btlink options_ssl" target="_blank">人工服务</a>&nbsp;&nbsp;|&nbsp;&nbsp;';
                              html += '<a href="javascript:;" class="btlink options_ssl"  data-type="perfect_user_info">完善资料</a>';
                              return html;
                            } else if (item.status === 1) {
                              var html = '';
                              switch (item.orderStatus) {
                                case "COMPLETE": //申请成功
                                  return '<a href="javascript:;" data-type="deploy_ssl" class="btlink options_ssl">部署</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="/ssl?action=download_cert&oid=' + item.oid + '" data-type="download_ssl" class="btlink options_ssl">下载</a>'
                                  break;
                                case "PENDING": //申请中
                                  if (item.install) html += '<a href="' + item.qq + '" class="btlink options_ssl" target="_blank">人工服务</a>&nbsp;&nbsp;|&nbsp;&nbsp;';
                                  html += '<a href="javascript:;" data-type="verify_order" class="btlink options_ssl">验证</a>';
                                  return html;
                                  break;
                                case "CANCELLED": //已取消
                                  return '无操作';
                                  break;
                                case "FAILED":
                                  return '<a href="javascript:;" data-type="info_order" class="btlink options_ssl">详情</a>';
                                  break;
                                default:
                                  if (item.install) html += '<a href="' + item.qq + '" class="btlink options_ssl" target="_blank">人工服务</a>&nbsp;&nbsp;|&nbsp;&nbsp;';
                                  html += '<a href="javascript:;" data-type="verify_order" class="btlink options_ssl">验证</a>';
                                  return html;
                                  break;
                              }
                            }
                          }()) + '</td>' +
                          '</tr>';
                      }
                    });
                    $('#ssl_order_list tbody').html(html);
                  });
                  robj.append('<div class="alert alert-success" style="padding: 10px 15px;"><div class="business_line" ><div class="business_info business_advantage" style="padding-top:0"><div class="business_advantage_item"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">企业级证书</span></div><div class="business_advantage_item"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">极速申请</span></div><div class="business_advantage_item"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">防劫持/防篡改</span></div><div class="business_advantage_item"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">提高SEO权重</span></div><div class="business_advantage_item"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">赔付保证</span></div><div class="business_advantage_item"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">不成功可退款</span></div><div class="business_advantage_item" style="width:50%"><span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span><span class="advantage_title">官方推荐(宝塔官网bt.cn也在使用)</span></div></div></div></div>\
                        <div class= "mtb10" >\
                        <button class="btn btn-success btn-sm btn-title ssl_business_application" type="button">申请证书</button>\
                        <span class="ml5"><a href="http://q.url.cn/CDfQPS?_type=wpa&amp;qidian=true" target="_blank" class="btlink"><img src="https://pub.idqqimg.com/qconn/wpa/button/button_old_41.gif" style="margin-right:5px;margin-left:3px;vertical-align: -1px;">售前客服: 3007255432</a></span>\
                        <div class="divtable mtb10 ssl_order_list"  style="height: 290px;overflow-y: auto;">\
                            <table class="table table-hover" id="ssl_order_list">\
                                <thead><tr><th width="120px">域名</th><th  width="220px">证书类型</th><th>到期时间</th><th>状态</th><th style="text-align:right;">操作</th></tr></thead>\
                                <tbody><tr><td colspan="5" style="text-align:center"><img src="/static/layer/skin/default/loading-2.gif" style="width:15px;vertical-align: middle;"><span class="ml5" style="vertical-align: middle;">正在获取证书列表，请稍后...</span></td></tr></tbody>\
                            </table>\
                        </div>\
                    </div><ul class="help-info-text c7">\
                        <li>申请之前，请确保域名已解析，如未解析会导致审核失败(包括根域名)</li>\
                        <li>有效期1年，不支持续签，到期后需要重新申请</li>\
                        <li>在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点</li>\
                        <li><a style="color:red;">如果您的站点有使用CDN、高防IP、反向代理、301重定向等功能，可能导致验证失败</a></li>\
                        <li><a style="color:red;">申请www.bt.cn这种以www为二级域名的证书，需绑定并解析顶级域名(bt.cn)，否则将验证失败</a></li>\
                        <li><a style="color:red;">商用证书相对于普通证书，具有更高的安全性、赔付保障和支持通配符和多域名等方式。<a class="btlink" target="_blank" href="https://www.racent.com/sectigo-ssl">点击查看</a></a></li>\
                    </ul>');
                  bt.fixed_table('ssl_order_list');
                  /**
                   * @description 对指定表单元素的内容进行效验
                   * @param {Object} el jqdom对象
                   * @param {String} name 表单元素name名称
                   * @param {*} value 表单元素的值
                   * @returns 返回当前元素的值
                   */
                  function check_ssl_user_info(el, name, value, config) {
                    el.css('borderColor', '#ccc');
                    var status;
                    switch (name) {
                      case 'domains':
                        var list = value.split('\n');
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '域名不能为空！',
                            color: 'red'
                          });
                          status = false;
                        }
                        if (!Array.isArray(list)) list = [list];
                        $.each(list, function (index, item) {
                          if (bt.check_domain(item)) {
                            var type = item.indexOf(),
                              index = null;
                            if (config.code.indexOf('multi') > -1) index = 0;
                            if (config.code.indexOf('wildcard') > -1) index = 1;
                            if (config.code.indexOf('wildcard') > -1 && config.code.indexOf('multi') > -1) index = 2;
                            switch (index) {
                              case 0:
                                if (list.length > config.limit) {
                                  set_info_tips(el, {
                                    msg: '多域名证书当前支持' + config.limit + '个域名，如需添加，请联系客服咨询！',
                                    color: 'red'
                                  });
                                  status = false;
                                } else if (list.length == 1) {
                                  set_info_tips(el, {
                                    msg: '当前为多域名证书(当前支持' + config.limit + '个域名)，至少需要2个域名或多个域名！',
                                    color: 'red'
                                  });
                                  status = false;
                                }
                                break;
                              case 1:
                                if (item.indexOf('*') != 0) {
                                  set_info_tips(el, {
                                    msg: '通配符域名格式错误,正确写法‘*.bt.cn’',
                                    color: 'red'
                                  });
                                  status = false;
                                }
                                break;
                              case 2:
                                if (list.length > config.limit) {
                                  set_info_tips(el, {
                                    msg: '多域名通配符证书支持' + config.limit + '个域名，如需添加，请联系客服咨询！！',
                                    color: 'red'
                                  });
                                  status = false;
                                } else if (list.length == 1) {
                                  set_info_tips(el, {
                                    msg: '当前为多域名通配符(当前支持' + config.limit + '个域名)，需要2个域名或多个域名！',
                                    color: 'red'
                                  });
                                  status = false;
                                }
                                if (item.indexOf('*') != 0) {
                                  set_info_tips(el, {
                                    msg: '通配符域名格式错误,正确写法‘*.bt.cn’',
                                    color: 'red'
                                  });
                                  status = false;
                                }
                                break;
                            }
                          } else {
                            if (value != '') {
                              set_info_tips(el, {
                                msg: '【 ' + item + ' 】' + ',域名格式错误！',
                                color: 'red'
                              });
                            } else {
                              set_info_tips(el, {
                                msg: '域名不能为空！',
                                color: 'red'
                              });
                            }
                            status = false;
                          }
                        });
                        value = list;
                        break;
                      case 'state':
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '所在省份不能为空！',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'city':
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '所在市/县不能为空！',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'city':
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '所在市/县不能为空！',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'organation':
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '公司名称不能为空，如为个人申请请输入个人姓名！',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'address':
                        if (value == '' && index > 0) {
                          set_info_tips(el, {
                            msg: '请输入公司详细地址，不可为空，具体要求见说明，',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'name':
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '用户姓名不能为空！',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'email':
                        if (value == '') {
                          set_info_tips(el, {
                            msg: '用户邮箱地址不能为空！',
                            color: 'red'
                          });
                          status = false;
                        }
                        if (!bt.check_email(value)) {
                          set_info_tips(el, {
                            msg: '用户邮箱地址格式错误！',
                            color: 'red'
                          });
                          status = false;
                        }
                        break;
                      case 'mobile':
                        if (value != '') {
                          if (!bt.check_phone(value)) {
                            set_info_tips(el, {
                              msg: '用户手机号码格式错误！',
                              color: 'red'
                            });
                            status = false;
                          }
                        }
                        break;
                      default:
                        status = value;
                        break;
                    }
                    if (typeof status == "boolean" && status === false) return false;
                    status = value;
                    return status;
                  }

                  /**
                   * @description 设置元素的提示和边框颜色
                   * @param {Object} el jqdom对象 
                   * @param {Object} config  = {
                   *  @param {String} config.msg 提示内容
                   *  @param {String} config.color 提示颜色
                   * }
                   */
                  function set_info_tips(el, config) {
                    $('html').append($('<span id="width_test">' + config.msg + '</span>'));
                    layer.tips(config.msg, el, {
                      tips: [1, config.color],
                      time: 3000
                    });
                    el.css('borderColor', config.color);
                    $('#width_test').remove();
                  }
                  /**
                   * @description 更换域名验证方式
                   * @param {Number} oid 域名订单ID
                   * @returns void
                   */
                  function again_verify_veiw(oid, is_success) {
                    var loads = bt.load('正在获取验证方式,请稍后...');
                    bt.send('get_verify_result', 'ssl/get_verify_result', {
                      oid: oid
                    }, function (res) {
                      loads.close();
                      var type = res.data.dcvList[0].dcvMethod;
                      loadT = bt.open({
                        type: 1,
                        title: '验证域名-' + (type ? '文件验证' : 'DNS验证'),
                        area: '520px',
                        btn: ['更改', '取消'],
                        content: '<div class="bt-form pd15"><div class="line"><span class="tname">验证方式</span><div class="info-r"><select class="bt-input-text mr5" name="file_rule" style="width:250px"></select></div></div>\
                                                    <ul class="help-info-text c7"><li>文件验证（HTTP）：确保网站能够通过http正常访问</li><li>文件验证（HTTPS）：确保网站已开启https，并且网站能够通过https正常访问</li><li>DNS验证：需要手动解析DNS记录值</li><li style="color:red">注意：验证方式仅支持更换一次，请谨慎操作</li></ul>\
                                                </div>',
                        success: function (layero, index) {
                          var _option_list = {
                              '文件验证(HTTP)': 'HTTP_CSR_HASH',
                              '文件验证(HTTPS)': 'HTTPS_CSR_HASH',
                              'DNS验证(CNAME解析)': 'CNAME_CSR_HASH'
                            },
                            _option = '';
                          $.each(_option_list, function (index, item) {
                            _option += '<option value="' + item + '" ' + (type == item ? 'selected' : '') + '>' + index + '</option>';
                          })
                          $('select[name=file_rule]').html(_option);
                        },
                        yes: function (index, layero) {
                          var new_type = $('select[name=file_rule]').val();
                          if (type == new_type) return layer.msg('重复的验证方式', {
                            icon: 2
                          })
                          var loads = bt.load('正在修改验证方式,请稍后...');
                          bt.send('again_verify', 'ssl/again_verify', {
                            oid: oid,
                            dcvMethod: new_type
                          }, function (res) {
                            loads.close();
                            if (res.status) layer.close(index);
                            bt.msg(res)
                          })
                        }
                      });
                    });
                  }
                  /**
                   * @description 验证域名
                   * @param {Number} oid 域名订单ID
                   * @returns void
                   */
                  function verify_order_veiw(oid, is_success) {
                    var loads = bt.load('正在获取验证结果,请稍后...');
                    bt.send('get_verify_result', 'ssl/get_verify_result', {
                      oid: oid
                    }, function (res) {
                      loads.close();
                      if (!res.status) {
                        bt.msg(res);
                        return false;
                      }
                      if (res.status == 'COMPLETE') {
                        site.ssl.reload();
                        return false;
                      }
                      var rdata = res.data;
                      var domains = [],
                        type = rdata.dcvList[0].dcvMethod != 'CNAME_CSR_HASH',
                        info = {};
                      $.each(rdata.dcvList, function (key, item) {
                        domains.push(item['domainName']);
                      });
                      if (type) {
                        info = {
                          fileName: rdata.DCVfileName,
                          fileContent: rdata.DCVfileContent,
                          filePath: '/.well-known/pki-validation/',
                          paths: res.paths,
                          kfqq: res.kfqq
                        };
                      } else {
                        info = {
                          dnsHost: rdata.DCVdnsHost,
                          dnsType: rdata.DCVdnsType,
                          dnsValue: rdata.DCVdnsValue,
                          paths: res.paths,
                          kfqq: res.kfqq
                        };
                      }
                      if (is_success) {
                        is_success({
                          type: type,
                          domains: domains,
                          info: info
                        });
                        return false;
                      }
                      loadT = bt.open({
                        type: 1,
                        title: '验证域名-' + (type ? '文件验证' : 'DNS验证'),
                        area: '620px',
                        content: reader_domains_cname_check({
                          type: type,
                          domains: domains,
                          info: info
                        }),
                        success: function (layero, index) {
                          var clipboard = new ClipboardJS('.parsing_info .parsing_icon');
                          clipboard.on('success', function (e) {
                            bt.msg({
                              status: true,
                              msg: '复制成功'
                            });
                            e.clearSelection();
                          });
                          clipboard.on('error', function (e) {
                            bt.msg({
                              status: true,
                              msg: '复制失败，请手动ctrl+c复制！'
                            });
                            console.error('Action:', e.action);
                            console.error('Trigger:', e.trigger);
                          });
                          $('.verify_ssl_domain').click(function () {
                            verify_order_veiw(oid);
                            layer.close(index);
                          });

                          $('.set_verify_type').click(function () {
                            again_verify_veiw(oid);
                            layer.close(index);
                          });

                          $('.return_ssl_list').click(function () {
                            layer.close(index);
                            $('#ssl_tabs span.on').click();
                          });
                          // 重新验证按钮
                          $('.domains_table').on('click', '.check_url_results', function () {
                            var _url = $(this).data('url'),
                              _con = $(this).data('content');
                            check_url_txt(_url, _con, this)
                          })
                        }
                      });
                    });
                  }

                  /**
                   * @description 重新验证
                   * @param {String} url 验证地址
                   * @param {String} content 验证内容
                   * @returns 返回验证状态
                   */
                  function check_url_txt(url, content, _this) {
                    var loads = bt.load('正在获取验证结果,请稍后...');
                    bt.send('check_url_txt', 'ssl/check_url_txt', {
                      url: url,
                      content: content
                    }, function (res) {
                      loads.close();
                      var html = '<span style="color:red">失败[' + res + ']</span><a href="https://www.bt.cn/bbs/thread-56802-1-1.html" target="_blank" class="bt-ico-ask" style="cursor: pointer;">?</a>'
                      if (res === '1') {
                        html = '<a class="btlink">通过</a>';
                      }
                      $(_this).parents('tr').find('td:nth-child(2)').html(html)
                    })
                  }

                  /**
                   * @description 渲染验证模板接口
                   * @param {Object} data 验证数据
                   * @returns void
                   */
                  function reader_domains_cname_check(data) {
                    var html = '';
                    if (data.type) {
                      var check_html = '<div class="bt-table domains_table" style="margin-bottom:20px"><div class="divtable"><table class="table table-hover"><thead><tr><th width="250">URL</th><th width="85">验证结果</th><th style="text-align:right;">操作</th></thead>'
                      var paths = data.info.paths
                      for (var i = 0; i < paths.length; i++) {
                        check_html += '<tr><td><span title="' + paths[i].url + '" class="lib-ssl-overflow-span-style">' + paths[i].url + '</span></td><td>' + (paths[i].status == 1 ? '<a class="btlink">通过</a>' : '<span style="color:red">失败[' + paths[i].status + ']</span><a href="https://www.bt.cn/bbs/thread-56802-1-1.html" target="_blank" class="bt-ico-ask" style="cursor: pointer;">?</a>') + '</td><td style="text-align:right;"><a href="javascript:bt.pub.copy_pass(\'' + paths[i].url + '\');" class="btlink">复制</a> | <a href="' + paths[i].url + '" target="_blank" class="btlink">打开</a> | <a data-url="' + paths[i].url + '" data-content="' + data.info.fileContent + '" class="btlink check_url_results">重新验证</a></td>'
                      }
                      check_html += '</table></div></div>'
                      html = '<div class="lib-ssl-parsing">\
                                                <div class="parsing_tips">请给以下域名【 <span class="highlight">' + data.domains.join('、') + '</span> 】添加验证文件，验证信息如下：</div>\
                                                <div class="parsing_parem"><div class="parsing_title">文件所在位置：</div><div class="parsing_info"><input type="text" name="filePath"  class="parsing_input border" value="' + data.info.filePath + '" readonly="readonly" style="width:350px;"/></div></div>\
                                                <div class="parsing_parem"><div class="parsing_title">文件名：</div><div class="parsing_info"><input type="text" name="fileName" class="parsing_input" value="' + data.info.fileName + '" readonly="readonly" style="width:350px;"/><span class="parsing_icon" data-clipboard-text="' + data.info.fileName + '">复制</span></div></div>\
                                                <div class="parsing_parem"><div class="parsing_title" style="vertical-align: top;">文件内容：</div><div class="parsing_info"><textarea name="fileValue"  class="parsing_textarea" readonly="readonly" style="width:350px;">' + data.info.fileContent + '</textarea><span class="parsing_icon" style="display: block;width: 60px;border-radius: 3px;" data-clipboard-text="' + data.info.fileContent + '">复制</span></div></div>' +
                        check_html +
                        '<div class="parsing_tips" style="font-size:13px;line-height: 24px;">· 请确保以上列表所有项都验证成功后点击【验证域名】重新提交验证</br>· 如长时间验证不通过，请通过【修改验证方式】更改为【DNS验证】</br>· SSL添加文件验证方式 ->> <a href="https://www.bt.cn/bbs/thread-56802-1-1.html" target="_blank" class="btlink" >查看教程</a> <span style="padding-left:60px">专属客服QQ：' + data.info.kfqq + '</span></div>\
                                                <div class="parsing_parem" style="padding: 0 55px;"><button type="submit" class="btn btn-success verify_ssl_domain">验证域名</button><button type="submit" class="btn btn-success set_verify_type">修改验证方式</button><button type="submit" class="btn btn-default return_ssl_list">返回列表</button></div>\
                                            </div>';
                    } else {
                      html = '<div class="lib-ssl-parsing">\
                                                <div class="parsing_tips">请给以下域名【 <span class="highlight">' + data.domains.join('、') + '</span> 】添加“' + data.info.dnsType + '”解析，解析参数如下：</div>\
                                                <div class="parsing_parem"><div class="parsing_title">主机记录：</div><div class="parsing_info"><input type="text" name="host" class="parsing_input" value="' + data.info.dnsHost + '" readonly="readonly" /><span class="parsing_icon" data-clipboard-text="' + data.info.dnsHost + '">复制</span></div></div>\
                                                <div class="parsing_parem"><div class="parsing_title">记录值：</div><div class="parsing_info"><input type="text" name="domains"  class="parsing_input" value="' + data.info.dnsValue + '" readonly="readonly" /><span class="parsing_icon" data-clipboard-text="' + data.info.dnsValue + '">复制</span></div></div>\
                                                <div class="parsing_tips" style="font-size:13px;line-height: 24px;">· 请确保以上列表所有项都验证成功后点击【验证域名】重新提交验证</br>· 如长时间验证不通过，请通过【修改验证方式】更改为【DNS验证】</br>· 如何添加域名解析，《<a href="https://cloud.tencent.com/document/product/302/3446" class="btlink" target="__blink">点击查看教程</a>》，和咨询服务器运营商。</div>\
                                                <div class="parsing_parem" style="padding: 0 55px;"><button type="submit" class="btn btn-success verify_ssl_domain">验证域名</button><button type="submit" class="btn btn-default set_verify_type">修改验证方式</button><button type="submit" class="btn btn-default return_ssl_list">返回列表</button></div>\
                                            </div>';
                    }
                    return html;
                  }
                  // 购买证书信息
                  function pay_ssl_business() {
                    var order_info = {},
                      user_info = {},
                      is_check = false;
                    pay_ssl_layer = bt.open({
                      type: 1,
                      title: '购买商业证书',
                      area: ['790px', '780px'],
                      content: '<div class="bt_business_ssl">\
                                                <div class="bt_progress_list">\
                                                    <div class="bt_progress_content">\
                                                        <div class="bt_progress_item active">\
                                                            <div class="bt_progress_info">1</div>\
                                                            <div class="bt_progress_title">选择产品</div>\
                                                        </div>\
                                                        <div class="bt_progress_item">\
                                                            <div class="bt_progress_info">2</div>\
                                                            <div class="bt_progress_title">支付订单</div>\
                                                        </div>\
                                                        <div class="bt_progress_item">\
                                                            <div class="bt_progress_info">3</div>\
                                                            <div class="bt_progress_title">完成支付</div>\
                                                        </div>\
                                                    </div>\
                                                </div>\
                                                <div class="bt_business_tab bt_business_form active">\
                                                    <div class="business_line">\
                                                        <div class="business_title">证书优势</div>\
                                                        <div class="business_info business_advantage">\
                                                            <div class="business_advantage_item">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">企业级证书</span>\
                                                            </div>\
                                                            <div class="business_advantage_item">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">极速申请</span>\
                                                            </div>\
                                                            <div class="business_advantage_item">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">防劫持/防篡改</span>\
                                                            </div>\
                                                            <div class="business_advantage_item">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">提高SEO权重</span>\
                                                            </div>\
                                                            <div class="business_advantage_item">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">赔付保证</span>\
                                                            </div>\
                                                            <div class="business_advantage_item">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">不成功可退款</span>\
                                                            </div>\
                                                            <div class="business_advantage_item" style="width:50%">\
                                                                <span class="advantage_icon glyphicon glyphicon glyphicon-ok"></span>\
                                                                <span class="advantage_title">官方推荐(宝塔官网bt.cn也在使用)</span>\
                                                            </div>\
                                                        </div>\
                                                    </div>\
                                                    <div class="business_line">\
                                                        <div class="business_title">证书分类</div>\
                                                        <div class="business_info business_type">\
                                                            <div class="ssl_type_item active" data-type="dv">\
                                                                <div class="ssl_type_title">域名型证书(DV)</div>\
                                                                <div class="ssl_type_ps">推荐个人博客、个人项目使用</div>\
                                                            </div>\
                                                            <div class="ssl_type_item" data-type="ov">\
                                                                <div class="ssl_type_title">企业型证书(OV)</div>\
                                                                <div class="ssl_type_ps">推荐企业官网、电商、教育、医疗等部门使用</div>\
                                                            </div>\
                                                            <div class="ssl_type_item" data-type="ev">\
                                                                <div class="ssl_type_title">增强型证书(EV)</div>\
                                                                <div class="ssl_type_ps">推荐银行、金融、保险、电子商务、中大型企业、政府机关等使用</div>\
                                                            </div>\
                                                        </div>\
                                                    </div>\
                                                    <div class="business_line">\
                                                        <div class="business_title">证书类型</div>\
                                                        <div class="business_info business_class">\
                                                            <div class="business_class_list"></div>\
                                                        </div>\
                                                    </div>\
                                                    <div class="business_line">\
                                                        <div class="business_title">域名数量</div>\
                                                        <div class="business_info">\
                                                            <div class="domain_number_group">\
                                                                <div class="domain_number_reduce is_disable" data-type="reduce"></div>\
                                                                <input type="number" class="domain_number_input" value=""/>\
                                                                <div class="domain_number_add"  data-type="add"></div>\
                                                            </div>\
                                                            <div class="domain_number_tips"></div>\
                                                        </div>\
                                                    </div>\
                                                    <div class="business_line">\
                                                        <div class="business_title">人工服务</div>\
                                                        <div class="business_info business_artificial">\
                                                            <div class="business_artificial_content"><div class="business_artificial_checkbox active"></div><div class="business_artificial_label"><span>--元/次</span>，付费安装服务，保证100%成功，不成功可全额退款。</div></div>\
                                                        </div>\
                                                    </div>\
                                                    <div class="business_line">\
                                                        <div class="business_title">总计费用</div>\
                                                        <div class="business_info business_cost">\
                                                            <span class="business_price_large">--</span>\
                                                            <span class="business_price_small">元/1年</span>\
                                                            <span class="business_original_price" style="display:none">原价<span>--</span>元/1年</span>\
                                                        </div>\
                                                    </div>\
                                                    <div class="business_line" style="margin-bottom:0;">\
                                                        <div class="business_info">\
                                                            <button type="button" class="business_pay">立即购买</button>\
                                                        </div>\
                                                    </div>\
                                                </div>\
                                                <div class="bt_business_tab ssl_applay_info">\
                                                    <div class="guide_nav"><span class="active">微信支付</span><span >支付宝支付</span></div>\
                                                    <div class="paymethod">\
                                                        <div class="pay-wx" id="PayQcode"></div>\
                                                    </div>\
                                                    <div class="lib-price-box text-center">\
                                                        <span class="lib-price-name f14"><b>总计</b></span>\
                                                        <span class="price-txt"><b class="sale-price"></b>元</span>\
                                                    </div>\
                                                    <div class="lib-price-detailed">\
                                                        <div class="info">\
                                                            <span class="text-left">商品名称</span>\
                                                            <span class="text-right"></span>\
                                                        </div>\
                                                        <div class="info">\
                                                            <span class="text-left">下单时间</span>\
                                                            <span class="text-right"></span>\
                                                        </div>\
                                                    </div>\
                                                    <div class="lib-prompt"><span>微信扫一扫支付</span></div>\
                                                </div>\
                                                <div class="bt_business_tab ssl_order_check">\
                                                    <div class="order_pay_title">支付成功</div>\
                                                    <div class="lib-price-detailed">\
                                                        <div class="info">\
                                                            <span class="text-left">商品名称</span>\
                                                            <span class="text-right"></span>\
                                                        </div>\
                                                        <div class="info">\
                                                            <span class="text-left">商品价格</span>\
                                                            <span class="text-right"></span>\
                                                        </div>\
                                                        <div class="info">\
                                                            <span class="text-left">下单时间</span>\
                                                            <span class="text-right"></span>\
                                                        </div>\
                                                    </div>\
                                                    <div class="order_pay_btn"><a href="javascript:;">人工服务</a><a href="javascript:;" data-type="info">完善证书资料</a><a href="javascript:;" data-type="clear">返回列表</a></div>\
                                                    <ul class="help-info-text c7" style="padding:15px 0 0 70px;font-size:13px;">\
                                                        <li>支付成功后请点击“完善证书资料”继续申请证书。</li>\
                                                        <li>如果已购买人工服务，请点击“人工服务”咨询帮助。</li>\
                                                    </ul>\
                                                </div>\
                                                <span style="position: absolute;bottom: 0;left: 0;right: 0;text-align: center;display: inline-block;height: 45px;line-height: 45px;background: #fafafafa;color: #ff0c00;font-size: 13px;">禁止诈骗、赌博、色情、木马、病毒等违法违规网站申请SSL证书，如有违反，撤销申请，停用账号</span>\
                                            </div>',
                      success: function (layero, indexs) {
                        var product_list = [],
                          product_current = {},
                          install_service = null,
                          add_domain_number = 0,
                          order_id = null,
                          qq_info = null;
                        $('.business_type .ssl_type_item').click(function () {
                          $(this).addClass('active').siblings().removeClass('active');
                          reader_product_list({
                            p_type: $(this).data('type')
                          }, function (res) {
                            if (parseInt(res.checked)) install_service = $('.business_artificial_checkbox').hasClass('active');
                            reader_product_info(product_list[0]);
                          });
                        });
                        $('.business_class .business_class_list').on('click', '.business_class_item', function () {
                          var index = $(this).data('index');
                          $(this).addClass('active').siblings().removeClass('active');
                          $('.domain_number_reduce').addClass('is_disable');
                          delete product_current.current_num;
                          reader_product_info(product_list[index]);
                          product_current = product_list[index];
                        });
                        $('.business_artificial_checkbox').click(function () {
                          if ($(this).hasClass('active')) {
                            $(this).removeClass('active');
                            is_additional_price(false, product_current);
                            install_service = false;
                          } else {
                            $(this).addClass('active');
                            is_additional_price(true, product_current);
                            install_service = true;
                          }
                        });
                        $('.business_artificial_label').click(function () {
                          $(this).prev().click();
                        });
                        $('.business_pay').click(function () {
                          var loadT = bt.load('正在生成支付订单，请稍后...'),
                            data = product_current,
                            num = 0;
                          if (typeof data.current_num == "undefined") data.current_num = data.num
                          if (data.add_price !== 0) num = parseInt(data.current_num - data.num);
                          bt.send('apply_cert_order_pay', 'ssl/apply_cert_order_pay', {
                            pdata: JSON.stringify({
                              pid: data.pid,
                              install: install_service ? 1 : 0,
                              num: num
                            })
                          }, function (res) {
                            loadT.close();
                            if (res.status) {
                              is_check = true;
                              $('.bt_progress_content .bt_progress_item:eq(1)').addClass('active');
                              $('.ssl_applay_info').addClass('active').siblings().removeClass('active');

                              reader_applay_qcode($.extend({
                                name: data.title + (install_service ? '(包含人工服务)' : ''),
                                price: (data.price + (install_service ? data.install_price : 0) + (((typeof data.current_num == "undefined" ? 0 : data.current_num) - data.num) * data.add_price)).toFixed(2),
                                time: bt.format_data(new Date().getTime())
                              }, res.msg), function (info) {
                                check_applay_status(function (rdata) {
                                  $('.bt_progress_content .bt_progress_item:eq(2)').addClass('active');
                                  $('.ssl_order_check').addClass('active').siblings().removeClass('active');
                                  $('.ssl_order_check .lib-price-detailed .text-right:eq(0)').html(info.name);
                                  $('.ssl_order_check .lib-price-detailed .text-right:eq(1)').html('￥' + info.price);
                                  $('.ssl_order_check .lib-price-detailed .text-right:eq(2)').html(info.time);
                                  $('#ssl_tabs .on').click();


                                }); //检测支付状态
                              }); //渲染二维码
                            }
                          });
                        });

                        $('.guide_nav span').click(function () {
                          var price = $('.business_price_large').text(),
                            is_wx_quota = parseFloat(price) >= 6000;
                          if ($(this).index() === 0 && is_wx_quota) {
                            layer.msg('微信单笔交易限额6000元,请使用支付宝支付', {
                              icon: 0
                            });
                          } else {
                            $(this).addClass('active').siblings().removeClass('active');
                            $('.lib-prompt span').html($(this).index() == 0 ? '微信扫一扫支付' : '支付宝扫一扫支付');
                            $('#PayQcode').empty();
                            $('#PayQcode').qrcode({
                              render: "canvas",
                              width: 200,
                              height: 200,
                              text: $(this).index() != 0 ? order_info.alicode : order_info.wxcode
                            });
                          }
                        });
                        $('.order_pay_btn a').click(function () {
                          switch ($(this).data('type')) {
                            case 'info':
                              confirm_certificate_info($.extend(product_current, {
                                oid: order_id,
                                qq: qq_info,
                                install: install_service,
                                limit: add_domain_number
                              }));
                              break;
                            case 'clear':
                              layer.close(indexs);
                              break;
                          }
                        });
                        $('.domain_number_reduce,.domain_number_add').click(function () {
                          if ($(this).hasClass('is_disable')) return false;
                          var type = $(this).data('type'),
                            data = product_current,
                            input = $('.domain_number_input'),
                            reduce = input.prev(),
                            add = input.next(),
                            min = parseInt(input.attr('min')),
                            max = parseInt(input.attr('max')),
                            input_val = parseInt(input.val());
                          switch (type) {
                            case 'reduce':
                              input_val--;
                              if (min > input_val < max) {
                                input.val(input_val);
                              }
                              break;
                            case 'add':
                              input_val++;
                              if (min > input_val < max) {
                                input.val(input_val);
                                add.removeClass('is_disable');
                              }
                              if (input_val == max) $(this).addClass('is_disable');
                              break;
                          }
                          if (input_val == min) {
                            reduce.addClass('is_disable');
                          } else if (input.val() == max) {
                            add.addClass('is_disable');
                          } else {
                            reduce.removeClass('is_disable');
                            add.removeClass('is_disable');
                          }
                          reader_product_info($.extend(product_current, {
                            current_num: input_val
                          }));
                        });
                        $('.domain_number_input').on('input', function () {
                          var input = $(this),
                            input_val = parseInt(input.val()),
                            input_min = parseInt(input.attr('min')),
                            input_max = parseInt(input.attr('max')),
                            reduce = input.prev(),
                            add = input.next();
                          if (input_val < input_min) {
                            input.val(input_min);
                          } else if (input_val > input_max) {
                            input.val(input_max);
                          }
                          if (input.val() == '') {
                            input.val(input_min);
                            input_val = input_min;
                          }
                          if (input_val == input_min) {
                            reduce.addClass('is_disable');
                          } else if (input_val == input_max) {
                            add.addClass('is_disable');
                          } else {
                            reduce.removeClass('is_disable');
                            add.removeClass('is_disable');
                          }
                          reader_product_info($.extend(product_current, {
                            current_num: parseInt(input.val())
                          }));
                        });
                        $('.business_type .ssl_type_item:eq(0)').click();

                        function reader_product_info(data) {
                          add_domain_number = data.current_num;
                          $('.business_original_price span').html(data.src_price);
                          $('.domain_number_input').val(data.current_num || data.num).attr('min', data.num);
                          $('.business_artificial .business_artificial_label span').html(data.install_price + '元/次');
                          is_additional_price(install_service, data);
                          if (data.add_price != 0) {
                            $('.domain_number_tips').html('每个域名<span>' + data.add_price + '元/个</span>，默认包含' + data.num + '个域名');
                            $('.domain_number_input').next().removeClass('is_disable');
                            $('.domain_number_input').attr('max', 999);
                          } else {
                            $('.domain_number_tips').empty();
                            $('.domain_number_input').next().addClass('is_disable');
                            $('.domain_number_input').attr('max', data.num);
                          }
                        }

                        function is_additional_price(status, data) {
                          var input = $('.domain_number_input').val();
                          if (status) {
                            $('.business_price_large').html(parseFloat(data.price + data.install_price + (data.add_price * (parseInt(input) - data.num))).toFixed(2));
                            $('.business_price_small').html('元/1年(包含人工服务)');
                          } else {
                            $('.business_price_large').html((data.price + (data.add_price * (parseInt(input) - data.num))).toFixed(2));
                            $('.business_price_small').html('元/1年');
                          }
                        }

                        function reader_product_list(data, callback) {
                          var html = '';
                          $('.business_class_list').html('<div class="business_class_loading">正在获取证书列表，请稍后...</div>')
                          bt.send('get_product_list', 'ssl/get_product_list', data, function (res) {
                            user_info = res.administrator;
                            product_list = res.data;
                            for (var i = 0; i < res.data.length; i++) {
                              var item = res.data[i];
                              html += '<div class="business_class_item ' + (i == 0 ? 'active' : '') + '" data-index="' + i + '"><div class="business_class_title">' + item.title + '</div><div class="business_class_original">原价' + item.other_price + '元/1年</div><div class="business_class_price">' + item.price.toFixed(2) + '元/1年</div></div>';
                            }
                            $('.business_class_list').html(html);
                            product_current = product_list[0];
                            if (callback) callback(res)
                          });
                        }

                        function reader_applay_qcode(data, callback) {
                          var price = $('.business_price_large').text(),
                            is_wx_quota = parseFloat(price) >= 6000;
                          order_id = data.oid;
                          qq_info = data.qq;
                          order_info = data
                          if (is_wx_quota) {
                            $('.guide_nav span:eq(1)').click();
                          } else {
                            $('#PayQcode').empty().qrcode({
                              render: "canvas",
                              width: 240,
                              height: 240,
                              text: data.wxcode
                            });
                          }
                          $('.price-txt .sale-price').html($('.business_price_large').text());
                          $('.lib-price-detailed .info:eq(0) span:eq(1)').html(data.name);
                          $('.lib-price-detailed .info:eq(1) span:eq(1)').html(data.time);
                          if (typeof data.qq != "undefined") {
                            $('.order_pay_btn a:eq(0)').attr({
                              'href': data.qq,
                              'target': '_blank'
                            });
                          } else {
                            $('.order_pay_btn a:eq(0)').remove();
                          }
                          if (callback) callback(data);
                        }

                        function check_applay_status(callback) {
                          bt.send('get_pay_status', 'ssl/get_pay_status', {
                            oid: order_id
                          }, function (res) {
                            if (res) {
                              is_check = false;
                              if (callback) callback(res);
                            } else {
                              if (!is_check) return false;
                              setTimeout(function () {
                                check_applay_status(callback);
                              }, 2000);
                            }
                          });
                        }
                      },
                      cancel: function (index) {
                        if (is_check) {
                          if (confirm('当前正在支付订单，是否取消？')) {
                            layer.close(index)
                            is_check = false;
                          }
                          return false;
                        }
                      }
                    });
                  }
                  // 确认证书信息
                  function confirm_certificate_info(config) {
                    var userLoad =  bt.load('正在获取用户信息，请稍后...');
                    bt.send('get_cert_admin', 'ssl/get_cert_admin', {}, function (res) {
                      userLoad.close();
                      var html = '';
                      if (typeof pay_ssl_layer != 'undefined') pay_ssl_layer.close();
                      if (config.code.indexOf('multi') > -1) {
                        if (config.code.indexOf('wildcard') > -1) {
                          placeholder = '多域名通配符证书，每行一个域名，支持' + config.limit + '个域名，必填项,例如：\r*.bt.cn\r*.bttest.cn';
                        } else {
                          placeholder = '多域名证书，每行一个域名，支持' + config.limit + '个域名，必填项,例如：\rwww.bt.cn\rwww.bttest.cn';
                        }
                        html = '<textarea class="bt-input-text mr20 key" name="domains" placeholder="' + placeholder + '" style="line-height:20px;width:400px;height:150px;padding:8px;"></textarea>';
                      } else {
                        if (config.code.indexOf('wildcard') > -1) {
                          placeholder = '请输入需要申请证书的域名（单域名通配符证书），必填项，例如：*.bt.cn';
                        } else {
                          placeholder = '请输入需要申请证书的域名（单域名证书），必填项，例如：www.bt.cn';
                        }
                        html = '<input type="text" disabled="true" readonly="readonly" id="apply_site_name" class="bt-input-text mr5" name="domains" placeholder="' + placeholder + '"/><button class="btn btn-success btn-xs" onclick="site.select_site_list(\'apply_site_name\',\'' + config.code + '\')" style="">选择已有域名</button><button class="btn btn-success btn-xs" onclick="site.select_site_txt(\'apply_site_name\')" style="margin: 5px;">自定义域名</button>';
                      }
                      bt.open({
                        type: 1,
                        title: '完善商业证书资料',
                        area: '610px',
                        content: '<form class="bt_form perfect_ssl_info" onsubmit="return false;">\
                                                    <div class="line">\
                                                        <span class="tname">证书信息</span>\
                                                        <div class="info-r">\
                                                            <span class="ssl_title">' + config.title + (config.limit > 1 ? ('<span style="margin-left:5px;">，包含' + config.limit + '个域名</span>') : '') + '</span>\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">域名</span>\
                                                        <div class="info-r domain_list_info" style="margin-bottom:-5px;">' + html + '</div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">验证方式</span>\
                                                        <div class="info-r">\
                                                            <label title="如网站未开启301、302、强制HTTPS、反向代理功能." class="mr20">\
                                                                <input type="radio" name="dcvMethod" checked="checked" value="HTTP_CSR_HASH">\
                                                                <span>文件验证(HTTP)</span>\
                                                            </label>\
                                                            <label title="如网站开启【强制HTTPS】，请选【HTTPS验证】" class="mr20">\
                                                                <input type="radio" name="dcvMethod" value="HTTPS_CSR_HASH">\
                                                                <span>文件验证(HTTPS)</span>\
                                                            </label>\
                                                            <label title="如网站还未备案完成，可选【DNS验证】." class="mr20">\
                                                                <input type="radio" name="dcvMethod" value="CNAME_CSR_HASH">\
                                                                <span>DNS验证(CNAME解析)</span>\
                                                            </label>\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">所在地区</span>\
                                                        <div class="info-r">\
                                                            <input type="text" class="bt-input-text mr5" name="state" value="' + res.state + '" placeholder="请输入所在省份，必填项" style="width: 190px; margin-right:0;" data-placeholder="请输入所在省份，必填项">\
                                                            <input type="text" class="bt-input-text mr5" name="city" value="' + res.city + '" placeholder="请输入所在市/县，必填项" style="width: 190px; margin-left: 15px;" data-placeholder="请输入所在市/县，必填项" />\
                                                        </div>\
                                                    </div>\
                                                    <div class="line" style="display:' + ((config.code.indexOf('ov') > -1 || config.code.indexOf('ev') > -1) ? 'block' : 'none') + '">\
                                                        <span class="tname">公司详细地址</span>\
                                                        <div class="info-r">\
                                                            <input type="text" class="bt-input-text mr5" name="address" value="' + res.address + '" placeholder="请输入公司详细地址，具体要求见说明，必填项" />\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">公司名称</span>\
                                                        <div class="info-r">\
                                                            <input type="text" class="bt-input-text mr5" name="organation" value="' + res.organation + '" placeholder="请输入公司名称，如为个人申请请输入个人姓名，必填项" />\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">姓名</span>\
                                                        <div class="info-r ">\
                                                            <input type="text" class="bt-input-text mr5" name="name" value="' + res.lastName + res.firstName + '" placeholder="请输入姓名，必填项" />\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">邮箱</span>\
                                                        <div class="info-r ">\
                                                            <input type="text" class="bt-input-text mr5" name="email" value="' + res.email + '" placeholder="请输入邮箱地址，必填项" />\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <span class="tname">手机</span>\
                                                        <div class="info-r">\
                                                            <input type="text" class="bt-input-text mr5" name="mobile" value="' + res.mobile + '" placeholder="请输入手机号码，若为空，则使用当前绑定手机号" />\
                                                        </div>\
                                                    </div>\
                                                    <div class="line">\
                                                        <div class="info-r"><button class="btn btn-success submit_ssl_info">提交资料</button></div>\
                                                    </div>\
                                                    <ul class="help-info-text c7 ssl_help_info" style="display:' + ((config.code.indexOf('ov') > -1 || config.code.indexOf('ev') > -1) ? 'block' : 'none') + '">\
                                                        <li>OV/EV证书申请流程条件：</li>\
                                                        <li>1、填写网站验证信息(文件验证或DNS验证)</li>\
                                                        <li>2、完成邮箱认证，根据CA发送的邮件完善邮件内容(中文填写即可)</li>\
                                                        <li>3、企查查或者爱企查、百度地图、114best能查询到相关企业信息，且公司名和公司地址完全匹配</li>\
                                                        <li>4、企查查或其他平台留下的电话能保证周一到周五(7:00 - 15:00)能接听到CA的认证电话，电话号码归属地来自美国，请留意接听。</li>\
                                                    </ul>\
                                                </form>',
                        success: function (layero, index) {
                          $('.perfect_ssl_info').on('focus', 'input[type=text],textarea', function () {
                            var placeholder = $(this).attr('placeholder');
                            $('html').append($('<span id="width_test">' + placeholder + '</span>'));
                            $(this).attr('data-placeholder', placeholder);
                            layer.tips(placeholder, $(this), {
                              tips: [1, '#20a53a'],
                              time: 0
                            });
                            $(this).attr('placeholder', '');
                            $('#width_test').remove();
                          }).on('blur', 'input[type=text],textarea', function () {
                            var name = $(this).attr('name'),
                              val = $(this).val();
                            layer.closeAll('tips');
                            $(this).attr('placeholder', $(this).attr('data-placeholder'));
                            check_ssl_user_info($(this), name, val, config);
                          })
                          $('.submit_ssl_info').click(function () {
                            var data = {},
                              form = $('.perfect_ssl_info').serializeObject(),
                              loadT = null;
                            $('.perfect_ssl_info').find('input,textarea').each(function () {
                              var name = $(this).attr('name'),
                                value = $(this).val(),
                                value = check_ssl_user_info($(this), name, value, config);
                              if (typeof value === "boolean") {
                                form = false;
                                return false;
                              }
                              form[name] = value;
                            });
                            if (typeof form == "boolean") return false;
                            if (!(config.code.indexOf('ov') > -1 || config.code.indexOf('ev') > -1)) form['address'] = form['state'] + form['city'];
                            if (typeof config.limit == "undefined") config.limit = config.num
                            if (form.domains.length != config.limit) {
                              bt.confirm({
                                title: '提示',
                                msg: '检测到当前证书支持' + config.limit + '个域名可以继续添加域名，是否忽略继续提交？'
                              }, function () {
                                req();
                              })
                              return false;
                            }
                            req();

                            function req() {
                              var loadT = bt.load('正在提交证书资料，请稍后...');
                              bt.send('apply_order_ca', 'ssl/apply_order_ca', {
                                pdata: JSON.stringify({
                                  pid: config.pid,
                                  oid: config.oid,
                                  domains: form.domains,
                                  dcvMethod: $("[name='dcvMethod']:checked").val(),
                                  Administrator: {
                                    job: '总务',
                                    postCode: '523000',
                                    country: 'CN',
                                    lastName: form.name,
                                    state: form.state,
                                    city: form.city,
                                    address: form.address,
                                    organation: form.organation,
                                    email: form.email,
                                    mobile: form.mobile,
                                    lastName: form.name
                                  }
                                })
                              }, function (res) {
                                loadT.close();
                                if (typeof res.msg == "object") {
                                  for (var key in res.msg.errors) {
                                    if (Object.hasOwnProperty.call(res.msg.errors, key)) {
                                      var element = res.msg.errors[key];
                                      bt.msg({
                                        status: false,
                                        msg: element
                                      });
                                    }
                                  }
                                } else {
                                  bt.msg(res);
                                }
                                if (res.status) {
                                  layer.close(index);
                                  verify_order_veiw(config.oid);
                                  $('#ssl_tabs span.on').click();
                                }
                              });
                            }
                          });
                        }
                      });
                    });
                  }
                  $('.ssl_business_application').click(function () {
                    pay_ssl_business();
                  });
                  //订单证书操作
                  $('.ssl_order_list').on('click', '.options_ssl', function () {
                    var type = $(this).data('type'),
                      tr = $(this).parents('tr');
                    itemData = order_list[tr.data('index')];
                    switch (type) {
                      case 'deploy_ssl': // 部署证书
                        bt.confirm({
                          title: '部署证书',
                          msg: '是否部署该证书,是否继续？<br>证书类型：' + itemData.title + ' <br>证书支持域名：' + itemData.domainName.join('、') + '<br>部署站点名:' + web.name + ''
                        }, function (index) {
                          var loads = bt.load('正在部署证书，请稍后...');
                          bt.send('set_cert', 'ssl/set_cert', {
                            oid: itemData.oid,
                            siteName: web.name
                          }, function (rdata) {
                            layer.close(index);
                            $('#webedit-con').empty();
                            site.edit.set_ssl(web);
                            site.ssl.reload()
                            bt.msg(rdata);
                          });
                        });
                        break;
                      case 'verify_order': // 验证订单
                        verify_order_veiw(itemData.oid);
                        break;
                      case 'clear_order': // 取消订单
                        bt.confirm({
                          title: '取消订单',
                          msg: '是否取消该订单，订单域名【' + itemData.domainName.join('、') + '】，是否继续？'
                        }, function (index) {
                          var loads = bt.load('正在取消订单，请稍后...');
                          bt.send('cancel_cert_order', 'ssl/cancel_cert_order', {
                            oid: itemData.oid
                          }, function (rdata) {
                            layer.close(index);
                            if (rdata.status) {
                              $('#ssl_tabs span:eq(2)').click();
                              setTimeout(function () {
                                bt.msg(rdata);
                              }, 2000);
                            }
                            bt.msg(rdata);
                          });
                        })
                        break;
                      case 'perfect_user_info': //完善用户信息
                        confirm_certificate_info(itemData);
                        break;
                    }
                  });
                } else {
                  robj.append('<div class="alert alert-warning" style="padding:10px">未绑定宝塔账号，请注册绑定，绑定宝塔账号(非论坛账号)可实现一键部署SSL</div>');
                  var datas = [{
                      title: '宝塔账号',
                      name: 'bt_username',
                      value: rdata.email,
                      width: '260px',
                      placeholder: '请输入手机号码'
                    },
                    {
                      title: '密码',
                      type: 'password',
                      name: 'bt_password',
                      value: rdata.email,
                      width: '260px'
                    },
                    {
                      title: ' ',
                      items: [{
                          text: '登录',
                          name: 'btn_ssl_login',
                          type: 'button',
                          callback: function (sdata) {
                            bt.pub.login_btname(sdata.bt_username, sdata.bt_password, function (ret) {
                              if (ret.status) site.reload(7);
                            })
                          }
                        },
                        {
                          text: '注册宝塔账号',
                          name: 'bt_register',
                          type: 'button',
                          callback: function (sdata) {
                            window.open('https://www.bt.cn/register.html')
                          }
                        }
                      ]
                    }
                  ]
                  for (var i = 0; i < datas.length; i++) {
                    var _form_data = bt.render_form_line(datas[i]);
                    robj.append(_form_data.html);
                    bt.render_clicks(_form_data.clicks);
                  }
                  robj.append(bt.render_help(['商用证书相对于普通证书，具有更高的安全性、赔付保障和支持通配符和多域名等方式。<a class="btlink" target="_blank" href="https://www.racent.com/sectigo-ssl">点击查看</a>', '已有宝塔账号请登录绑定']));
                }
              });
            }
          },
          {
            title: "Let's Encrypt",
            callback: function (robj) {
              acme.get_account_info(function (let_user) {});
              acme.id = web.id;
              if (rdata.status && rdata.type == 1) {
                var cert_info = '';
                if (rdata.cert_data['notBefore']) {
                  cert_info = '<div style="margin-bottom: 10px;" class="alert alert-success">\
                                        <p style="margin-bottom: 9px;"><span style="width: 357px;display: inline-block;"><b>已部署成功：</b>将在距离到期时间1个月内尝试自动续签</span>\
                                        <span style="margin-left: 15px;display: inline-block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width: 140px;width: 140px;">\
                                        <b>证书品牌：</b>' + rdata.cert_data.issuer + '</span></p>\
                                        <span style="display:inline-block;max-width: 357px;overflow:hidden;text-overflow:ellipsis;vertical-align:-3px;white-space: nowrap;width: 357px;"><b>认证域名：</b> ' + rdata.cert_data.dns.join('、') + '</span>\
                                        <span style="margin-left: 15px;"><b>到期时间：</b> ' + rdata.cert_data.notAfter + '</span></div>'
                }
                robj.append('<div>' + cert_info + '<div><span>密钥(KEY)</span><span style="padding-left:194px">证书(PEM格式)</span></div></div><div class="mask-tips" style="display:none;background: #fff;position: fixed;z-index: 1;width: 640px;height: 230px;line-height: 220px;font-size: 24px;text-align: center;padding: 10px 20px;border: 1px dashed #ccc;border-radius: 5px;margin-top: 5px;">IIS证书为二进制文件，无法显示</div>');
                var datas = [{
                    items: [{
                        name: 'key',
                        width: '45%',
                        height: '220px',
                        type: 'textarea',
                        value: rdata.key
                      },
                      {
                        name: 'csr',
                        width: '45%',
                        height: '220px',
                        type: 'textarea',
                        value: rdata.csr
                      }
                    ]
                  },
                  {
                    items: [{
                        text: '关闭SSL',
                        name: 'btn_ssl_close',
                        hide: !rdata.status,
                        type: 'button',
                        callback: function (sdata) {
                          site.ssl.set_ssl_status('CloseSSLConf', web.name);
                        }
                      },
                      {
                        text: '续签',
                        name: 'btn_ssl_renew',
                        hide: !rdata.status,
                        type: 'button',
                        callback: function (sdata) {
                          site.ssl.renew_ssl(web.name, rdata.auth_type, rdata.index);
                        }
                      }
                    ]
                  }
                ]
                for (var i = 0; i < datas.length; i++) {
                  var _form_data = bt.render_form_line(datas[i]);
                  robj.append(_form_data.html);
                  bt.render_clicks(_form_data.clicks);
                }
                if (rdata.csr == undefined && rdata.key == undefined) $('.mask-tips').show()
                robj.find('textarea').css('background-color', '#f6f6f6').attr('readonly', true);
                var helps = [
                  '申请之前，请确保域名已解析，如未解析会导致审核失败(包括根域名)',
                  '宝塔SSL申请的是免费版TrustAsia DV SSL CA - G5证书，仅支持单个域名申请',
                  '有效期1年，不支持续签，到期后需要重新申请',
                  '建议使用二级域名为www的域名申请证书,此时系统会默认赠送顶级域名为可选名称',
                  '在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点',
                  '如果重新申请证书时提示【订单已存在】请登录宝塔官网删除对应SSL订单',
                ]
                robj.append(bt.render_help(['已为您自动生成Let\'s Encrypt免费证书；', '如需使用其他SSL,请切换其他证书后粘贴您的KEY以及PEM内容，然后保存即可。']));
                return;
              }
              bt.site.get_site_domains(web.id, function (ddata) {
                var helps = [
                  [
                    '申请之前，请确保域名已解析，如未解析会导致审核失败',
                    'Let\'s Encrypt免费证书，有效期3个月，支持多域名。默认会自动续签',
                    '若您的站点使用了CDN或301重定向会导致续签失败',
                    '在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点'
                  ],
                  [
                    '在DNS验证中，我们提供了多种自动化DNS-API，并提供了手动模式',
                    '使用DNS接口申请证书可自动续期，手动模式下证书到期后需重新申请',
                    '使用【DnsPod/阿里云DNS】等接口前您需要先在弹出的窗口中设置对应接口的API'
                  ]
                ]
                var datas = [{
                  title: '验证方式',
                  items: [{
                      name: 'check_file',
                      text: '文件验证',
                      type: 'radio',
                      callback: function (obj) {
                        $('.checks_line').remove()
                        $(obj).siblings().removeAttr('checked');

                        $('.help-info-text').html($(bt.render_help(helps[0])).html());
                        //var _form_data = bt.render_form_line({ title: ' ', class: 'checks_line label-input-group', items: [{ name: 'force', type: 'checkbox', value: true, text: '提前校验域名(提前发现问题,减少失败率)' }] });
                        //$(obj).parents('.line').append(_form_data.html);

                        $('#ymlist li input[type="checkbox"]').each(function () {
                          if ($(this).val().indexOf('*') >= 0) {
                            $(this).parents('li').hide();
                          }
                        })
                      }
                    },
                    {
                      name: 'check_dns',
                      text: 'DNS验证(支持通配符)',
                      type: 'radio',
                      callback: function (obj) {
                        $('.checks_line').remove();
                        $(obj).siblings().removeAttr('checked');
                        $('.help-info-text').html($(bt.render_help(helps[1])).html());
                        $('#ymlist li').show();

                        var arrs_list = [],
                          arr_obj = {};
                        bt.site.get_dns_api(function (api) {
                          site.dnsapi = {}

                          for (var x = 0; x < api.length; x++) {
                            site.dnsapi[api[x].name] = {}
                            site.dnsapi[api[x].name].s_key = "None"
                            site.dnsapi[api[x].name].s_token = "None"
                            if (api[x].data) {
                              site.dnsapi[api[x].name].s_key = api[x].data[0].value
                              site.dnsapi[api[x].name].s_token = api[x].data[1].value
                            }
                            arrs_list.push({
                              title: api[x].title,
                              value: api[x].name
                            });
                            arr_obj[api[x].name] = api[x];
                          }

                          var data = [{
                            title: '选择DNS接口',
                            class: 'checks_line',
                            items: [{
                              name: 'dns_select',
                              width: '120px',
                              type: 'select',
                              items: arrs_list,
                              callback: function (obj) {
                                var _val = obj.val();
                                $('.set_dns_config').remove();
                                var _val_obj = arr_obj[_val];
                                var _form = {
                                  title: '',
                                  area: '530px',
                                  list: [],
                                  btns: [{
                                    title: '关闭',
                                    name: 'close'
                                  }]
                                };

                                var helps = [];
                                if (_val_obj.data !== false) {
                                  _form.title = '设置【' + _val_obj.title + '】接口';
                                  helps.push(_val_obj.help);
                                  var is_hide = true;
                                  for (var i = 0; i < _val_obj.data.length; i++) {
                                    _form.list.push({
                                      title: _val_obj.data[i].name,
                                      name: _val_obj.data[i].key,
                                      value: _val_obj.data[i].value
                                    })
                                    if (!_val_obj.data[i].value) is_hide = false;
                                  }
                                  _form.btns.push({
                                    title: '保存',
                                    css: 'btn-success',
                                    name: 'btn_submit_save',
                                    callback: function (ldata, load) {
                                      bt.site.set_dns_api({
                                        pdata: JSON.stringify(ldata)
                                      }, function (ret) {
                                        if (ret.status) {
                                          load.close();
                                          robj.find('input[type="radio"]:eq(0)').trigger('click')
                                          robj.find('input[type="radio"]:eq(1)').trigger('click')
                                        }
                                        bt.msg(ret);
                                      })
                                    }
                                  })
                                  if (is_hide) {
                                    obj.after('<button class="btn btn-default btn-sm mr5 set_dns_config">设置</button>');
                                    $('.set_dns_config').click(function () {
                                      var _bs = bt.render_form(_form);
                                      $('div[data-id="form' + _bs + '"]').append(bt.render_help(helps));
                                    })
                                  } else {
                                    var _bs = bt.render_form(_form);
                                    $('div[data-id="form' + _bs + '"]').append(bt.render_help(helps));
                                  }
                                }
                              }
                            }, ]
                          }, {
                            title: ' ',
                            class: 'checks_line label-input-group',
                            items: [{
                              css: 'label-input-group ptb10',
                              text: '自动组合泛域名',
                              name: 'app_root',
                              type: 'checkbox'
                            }]
                          }]
                          for (var i = 0; i < data.length; i++) {
                            var _form_data = bt.render_form_line(data[i]);
                            $(obj).parents('.line').append(_form_data.html)
                            bt.render_clicks(_form_data.clicks);
                          }
                        })
                      }
                    },
                  ]
                }]

                for (var i = 0; i < datas.length; i++) {
                  var _form_data = bt.render_form_line(datas[i]);
                  robj.append(_form_data.html);
                  bt.render_clicks(_form_data.clicks);
                }
                var _ul = $('<ul id="ymlist" class="domain-ul-list"><li style="cursor: pointer;"><input class="checkbox-text" type="checkbox" value="all"><span>全选</span></li></ul>');
                for (var i = 0; i < ddata.domains.length; i++) {
                  if (ddata.domains[i].binding === true) continue
                  _ul.append('<li style="cursor: pointer;"><input class="checkbox-text" type="checkbox" value="' + ddata.domains[i].name + '" ><span>' + ddata.domains[i].name + '</span></li>');
                }
                var _line = $("<div class='line mtb10'></div>");
                _line.append('<span class="tname text-center">域名</span>');
                _line.append(_ul);
                robj.append(_line);
                robj.find('input[type="radio"]').parent().addClass('label-input-group ptb10');


                $("#ymlist li input").click(function (e) {
                  if ($(this).prop("checked")) {
                    $(this).prop("checked", false)
                    if ($(this).val() == 'all') {
                      $("#ymlist input[type = 'checkbox']").prop('checked', false);
                    }
                  } else {
                    $(this).prop("checked", true);
                    if ($(this).val() == 'all') {
                      $("#ymlist input[type = 'checkbox']").prop('checked', true);
                    }
                  }
                  // e.stopPropagation();
                })
                $("#ymlist li").click(function () {

                  var o = $(this).find("input");
                  if (o.prop("checked")) {
                    o.prop("checked", false)
                    if (o.val() == 'all') {
                      $("#ymlist input[type = 'checkbox']").prop('checked', false);
                    }
                  } else {
                    o.prop("checked", true);
                    if (o.val() == 'all') {
                      $("#ymlist input[type = 'checkbox']").prop('checked', true);
                    }
                  }
                })
                var _btn_data = bt.render_form_line({
                  title: ' ',
                  text: '申请',
                  name: 'letsApply',
                  type: 'button',
                  callback: function (ldata) {
                    ldata['domains'] = [];
                    $('#ymlist input[type="checkbox"]:checked').each(function () {
                      if ($(this).val() != 'all') {
                        if ($(this).parents('li').is(":visible")) {
                          ldata['domains'].push($(this).val())
                        }
                      }
                    });
                    var auth_type = 'http'
                    var auth_to = web.id
                    var auto_wildcard = '0'
                    if (ldata.check_dns) {
                      auth_type = 'dns'
                      auth_to = 'dns'
                      auto_wildcard = ldata.app_root ? '1' : '0'
                      if (ldata.dns_select !== auth_to) {
                        if (!site.dnsapi[ldata.dns_select].s_key) {
                          layer.msg("指定dns接口没有设置密钥信息");
                          return;
                        }
                        auth_to = ldata.dns_select + "|" + site.dnsapi[ldata.dns_select].s_key + "|" + site.dnsapi[ldata.dns_select].s_token;
                      }
                    }
                    acme.apply_cert(ldata['domains'], auth_type, auth_to, auto_wildcard, function (res) {
                      site.ssl.ssl_result(res, auth_type, web.name);
                    })
                  }
                });
                robj.append(_btn_data.html);
                bt.render_clicks(_btn_data.clicks);
                robj.append(bt.render_help(helps[0]));
                robj.find('input[type="radio"]:eq(0)').trigger('click');
              })
            }
          },

          {
            title: "其他证书",
            callback: function (robj) {
              var cert_info = '';
              if (rdata.cert_data) {
                cert_info = '<div style="margin-bottom: 10px;" class="alert alert-success">\
                                        <p style="margin-bottom: 9px;"><span style="width: 306px;display: inline-block;">' + (rdata.status ? '<b>已部署成功：</b>请在证书到期之前更换新的证书' : '<b style="color:red;">当前未部署：</b>请点击【保存】按钮完成此证书的部署') + '</span>\
                                        <span style="margin-left: 20px;display: inline-block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width: 138px;width: 140px;">\
                                        <b>证书品牌：</b>' + rdata.cert_data.issuer + '</span></p>\
                                        <span style="display:inline-block;max-width: 306px;overflow:hidden;text-overflow:ellipsis;vertical-align:-3px;white-space: nowrap;width: 357px;"><b>认证域名：</b> ' + rdata.cert_data.dns.join('、') + '</span>\
                                        <span style="margin-left: 20px;"><b>到期时间：</b> ' + rdata.cert_data.notAfter + '</span></div>'
              }
              var datas = []
              var helps = []
              if (bt.get_cookie('serverType') == 'iis') {
                robj.append("<div>" + cert_info + "</div>")
                robj.append('<button class="btn btn-success btn-sm" onclick="site.upload_pfx(\'' + web.id + '\',\'' + web.name + '\')" style="margin-top:10px">导入证书</button>')
                robj.append("<div class=\"divtable mtb15 table-fixed-box\" style=\"max-height:200px;overflow-y: auto;\"><table id='bt_ssl_list' class='table table-hover'></table></div>")
                bt.render({
                  table: '#bt_ssl_list',
                  columns: [{
                      field: 'name',
                      title: '证书列表'
                    },
                    {
                      field: 'opt',
                      align: 'right',
                      width: '100px',
                      title: '操作',
                      templet: function (item) {
                        var opt = '<a class="btlink set-ssl" href="javascript:;">部署</a> | <a class="btlink del-ssl" href="javascript:;">删除</a>'
                        if (item.setup) {
                          opt = '已部署 | <a class="btlink" onclick="site.ssl.set_ssl_status(\'CloseSSLConf\',\'' + web.name + '\')" >关闭</a>';
                        }
                        return opt;
                      }
                    }
                  ],
                  data: rdata.data
                })
                bt.fixed_table('bt_ssl_list');
                $('a.set-ssl').click(function () {
                  var _this = $(this);
                  var item = $(this).parents('tr').data('item')

                  bt.site.set_ssl(web.name, {
                    cerName: item.name,
                    password: item.password
                  }, function (ret) {
                    if (ret.status) site.reload(7);
                    if (ret.msg.indexOf('password') >= 0) {
                      var index = layer.open({
                        type: 1,
                        skin: 'demo-class',
                        area: '350px',
                        title: '填写证书密码',
                        closeBtn: 2,
                        shift: 5,
                        shadeClose: false,
                        content: "<div class='bt-form pd20 pb70' >\
							                        <div class='line'>\
							                        <span class='tname'>证书密码:</span><div class='info-r '><input  type='text' value='bt.cn' class='bt-input-text new_password' /></div>\
							                        </div>\
							                        <ul class='help-info-text c7'>\
								                        <li>在此处填写pfx证书密码!</li>\
								                        <li>宝塔证书默认密码bt.cn,其他证书咨询证书提供商!</li>\
							                        </ul>\
					                                <div class='bt-form-submit-btn'>\
								                        <button type='button' class='btn btn-danger btn-sm btn-title' onclick='layer.closeAll()'>取消</button>\
						                                <button type='button' class='btn btn-success btn-sm btn-title btnOtherSSL' >提交</button>\
					                                </div>\
					                                </div>"
                      });
                      setTimeout(function () {
                        $(".btnOtherSSL").click(function () {
                          item.password = $(".new_password").val();
                          _this.parents('tr').data('item', item)
                          _this.trigger('click');
                          layer.close(index);
                        })
                      }, 100)

                    }
                  })
                })
                $('a.del-ssl').click(function () {
                  var _item = $(this).parents('tr').data('item');
                  bt.confirm({
                    msg: "是否确定删除" + _item.name + "？",
                    title: '提示'
                  }, function () {
                    var loading = bt.load()
                    bt.send("del_iis_other_ssl", 'site/del_iis_other_ssl', {
                      filename: _item.name
                    }, function (rdata) {
                      loading.close();
                      if (rdata.status) {
                        site.reload();
                      }
                      bt.msg(rdata);
                    })
                  })
                })
                helps = ['IIS证书格式为.pfx文件', '宝塔证书密码为bt.cn,其他证书密码在证书目录password文件', '手动导入Let\'s Encrypt证书一律不支持续签功能']
                if (bt.get_cookie('serverType') == 'iis') {
                  helps.push('<span style="color:red">IIS8.5以下版本，一台服务器只能存在一个SSL，多次部署会替换之前的SSL</span>')
                }
              } else {

                helps = [
                  '粘贴您的*.key以及*.pem内容，然后保存即可<a href="http://www.bt.cn/bbs/thread-704-1-1.html" class="btlink" target="_blank">[帮助]</a>。',
                  '如果浏览器提示证书链不完整,请检查是否正确拼接PEM证书',
                  'PEM格式证书 = 域名证书.crt + 根证书(root_bundle).crt',
                  '在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点',
                  '<span color="red">免费证书最长有效期为1年，如显示到期时间超过一年，并且造成apache/nginx无法启动，请正确填写SSL证书.</span>'
                ]

                robj.append('<div>' + cert_info + '<div><span>密钥(KEY)</span><span style="padding-left:194px">证书(PEM格式)</span></div></div>');
                datas = [{
                    items: [{
                        name: 'key',
                        width: '45%',
                        height: '220px',
                        type: 'textarea',
                        value: rdata.key
                      },
                      {
                        name: 'csr',
                        width: '45%',
                        height: '220px',
                        type: 'textarea',
                        value: rdata.csr
                      }
                    ]
                  },
                  {
                    items: [{
                        text: '保存',
                        name: 'btn_ssl_save',
                        type: 'button',
                        callback: function (sdata) {
                          bt.site.set_ssl(web.name, sdata, function (ret) {
                            if (ret.status) site.reload(7);
                            bt.msg(ret);
                          })
                        }
                      },
                      {
                        text: '关闭SSL',
                        name: 'btn_ssl_close',
                        hide: rdata.status == false,
                        type: 'button',
                        callback: function (sdata) {
                          site.ssl.set_ssl_status('CloseSSLConf', web.name);
                        }
                      }
                    ]
                  }
                ]
                for (var i = 0; i < datas.length; i++) {
                  var _form_data = bt.render_form_line(datas[i]);
                  robj.append(_form_data.html);
                  bt.render_clicks(_form_data.clicks);
                }
              }
              robj.append(bt.render_help(helps));

            }
          },
                    {
            title: '宝塔SSL',
            on: true,
            callback: function (robj) {
              bt.pub.get_user_info(function (udata) {
                if (udata.status) {
                  bt.site.get_domains(web.id, function (ddata) {
                    //IIS特殊处理                                       
                    var domains = [];
                    for (var i = 0; i < ddata.length; i++) {
                      if (ddata[i].name.indexOf('*') == -1) domains.push({
                        title: ddata[i].name,
                        value: ddata[i].name
                      });
                    }
	                  robj.append("<div style=\"margin-bottom: 10px;\" class=\"alert alert-danger\">因运营商资费及服务条件的调整，此证书已下架，如需使用免费SSL，请使用Let's Encrypt申请</div><button name=\"btsslApply\" class=\"btn btn-success btn-sm mr5 btsslApply disabled \">申请证书</button><div id='ssl_order_list' class=\"divtable mtb15 table-fixed-box\" style=\"max-height:320px;overflow-y: auto;\"><table id='bt_order_list' class='table table-hover'><thead><tr><th>域名</th><th>到期时间</th><th>状态</th><th>操作</th></tr></thead><tbody><tr><td colspan='4' style='text-align:center'><img style='height: 18px;margin-right:10px' src='/static/layer/skin/default/loading-2.gif'>正在获取订单,请稍后...</td></tr></tbody></table></div>");

                    $('.btsslApply').click(function(){
                    	layer.msg('因运营商资费及服务条件的调整，此证书已下架，如需使用免费SSL，请使用Let\'s Encrypt申请',{icon:0,closeBtn:2,time:0})
                    	return false
                      var is_pay = true;
                      /**
                       * @description 获取支付订单
                       * @Date 2021-03-31 11:11:19
                       * @param {function} callback 回调函数
                       * @return 
                      */
                      function getDvPaycode(callback){
                        bt_tools.send('ssl/get_dv_paycode',function (res) {
                          if(callback) callback(res)
                        },{plugin:true,load:'获取支付订单'});
                      }
                      /**
                      * @description 渲染支付视图
                      * @Date 2021-03-31 11:51:52
                      * @param {string} el 选择器 
                      * @param {object} config 配置文件{money:支付金额,productName:产品名称,orderTime:订单时间} 
                      * @return {object} {html:模板,event:事件绑定}
                      */
                      function readerApplayView(el,config){
                        html = '<div class="ssl_applay_info">\
                          <div class="guide_nav"><span class="active">微信支付</span><span>支付宝支付</span></div>\
                          <div class="paymethod"><div class="pay-wx" id="payQcode"></div></div>\
                          <div class="lib-price-box text-center">\
                            <span class="lib-price-name f14"><b>总计</b></span><span class="price-txt"><b class="sale-price">'+config.money+'</b>元</span>\
                          </div>\
                          <div class="lib-tips-title text-center f14 c6" style="position: relative;top:15px;">因运营商资费及服务条件的调整，如需使用免费SSL，请使用Let\'s Encrypt申请</div>\
                          <div class="lib-price-detailed">\
                            <div class="info">\
                              <span class="text-left">商品名称</span>\
                              <span class="text-right">'+config.productName+'</span>\
                            </div>\
                            <div class="info">\
                              <span class="text-left">下单时间</span>\
                              <span class="text-right">'+config.orderTime+'</span>\
                            </div>\
                          </div>\
                          <div class="lib-prompt"><span>微信扫一扫支付</span></div>\
                        </div>'
                        $(el).html(html);
                        $('#payQcode').empty().qrcode(config.wxcode);
                        $('.ssl_applay_info .guide_nav span').click(function(){
                          $(this).addClass('active').siblings().removeClass('active');
                          $('#payQcode').empty().qrcode($(this).index() == 0?config.wxcode:config.alicode);
                          $('.lib-prompt span').text($(this).index() == 0?'微信扫一扫支付':'支付宝扫一扫支付')
                        });
                      }

                      /**
                      * @description 递归请求
                      * @Date 2021-03-31 11:58:24
                      * @param {string} url 请求路径
                      * @param {object} data 请求参数
                      * @param {function} callback 回调函数
                      * @param {number} 递归延迟时间
                      * @return {*}
                      */ 
                      function recursionRequest(url,data,callback,time){
                        if(!is_pay) return false;
                        if(typeof data == "function"){
                          if(typeof callback == 'undefined'){
                            time = time || 1500,callback = data,data = {}
                          }else{
                            time = callback,callback = data,data = {}
                          }
                        }
                        time = time || 1500
                        bt_tools.send(url,data,function (res){
                          if(!callback(res,callback,time)){
                            setTimeout(function (){
                              recursionRequest(url,data,callback,time)
                            },time)
                          }
                        },{plugin:true,load:false});
                      }

                      getDvPaycode(function(res){
                        bt.open({
                          type: 1,
                          title: '购买宝塔SSL证书',
                          area: ['610px','720px'],
                          content:'<div class="ssl_pay_view" style="padding-bottom:25px"></div>',
                          success:function(layers,indexs) {
                            readerApplayView('.ssl_pay_view',{money:res.price,productName:'TrustAsia DV SSL CA - G5证书',orderTime:bt.format_data(new Date().getTime()),wxcode:res.wxcode,alicode:res.alicode})
                            recursionRequest('ssl/get_dv_paystatus',{ssl_id:res.oid},function(res){
                              if(res){
                                layer.close(indexs)
                                  site.ssl.setupDomainInfo(res.oid, domains, $(this).data('path'))
                                return true;
                              }
                            })
                          },
                          end:function(){ 
                            is_pay = false;
                          }
                        })
                      })
                    });
                    var helps = [
                      '申请之前，请确保域名已解析，如未解析会导致审核失败(包括根域名)',
                      '宝塔SSL申请的是TrustAsia DV SSL CA - G5证书，仅支持单个域名申请',
                      '有效期1年，不支持续签，到期后需要重新申请',
                      '建议使用二级域名为www的域名申请证书,此时系统会默认赠送顶级域名为可选名称',
                      '在未指定SSL默认站点时,未开启SSL的站点使用HTTPS会直接访问到已开启SSL的站点',
                      '宝塔SSL申请注意事项及教程 <a href="https://www.bt.cn/bbs/thread-33113-1-1.html" target="_blank" class="btlink"> 使用帮助</a>'
                    ]
                    if (bt.get_cookie('serverType') == 'iis') {
                      helps.push('<span style="color:red">IIS8.5以下版本，一台服务器只能存在一个SSL，多次部署会替换之前的SSL</span>')
                    }
                    robj.append(bt.render_help(helps));
                    bt.site.get_order_list(web.name, function (odata) {
                      if (odata.status === false) {
                        $("#bt_order_list tr:eq(1) td").text(odata.msg);
                        return;
                      }
                      $("#ssl_order_list").html("<table id='bt_order_list' class='table table-hover'></table>");
                      $('#ssl_order_list').on('click','.setupDomainInfo',function(){
                          site.ssl.setupDomainInfo($(this).data('ssl'), domains, web.path);
                      })
                      bt.render({
                        table: '#bt_order_list',
                        columns: [{
                            field: 'commonName',
                            title: '域名',
                            templet:function (item) { 
                              if(item.authDomain != '') return item.commonName
                              return "--"
                            }
                          },
                          {
                            field: 'endtime',
                            width: '70px',
                            title: '到期时间',
                            templet: function (item) {
                              return bt.format_data(item.endtime, 'yyyy/MM/dd');
                            }
                          },
                          {
                            field: 'stateName',
                            width: '100px',
                            title: '状态',
                            templet:function(item){ 
                              if(item.stateName != '') return item.stateName
                              return "待完善"
                            }
                          },
                          {
                            field: 'opt',
                            align: 'right',
                            width: '100px',
                            title: '操作',
                            templet: function (item) {
                              var opt = '<a class="btlink" onclick="site.ssl.onekey_ssl(\'' + item.partnerOrderId + '\',\'' + web.name + '\')" href="javascript:;">部署</a>'
                              if (item.stateCode == 'WF_DOMAIN_APPROVAL') {
                                opt = '<a class="btlink" onclick="site.ssl.verify_domain(\'' + item.partnerOrderId + '\',\'' + web.name + '\')" href="javascript:;">验证域名</a>';
                              } else {
                                if (item.setup) opt = '已部署 | <a class="btlink" href="javascript:site.ssl.set_ssl_status(\'CloseSSLConf\',\'' + web.name + '\')">关闭</a>'
                              }
                                if (item.authDomain == '') return '<a class="btlink setupDomainInfo"  data-ssl="' + item.ssl_id + '" data-path="' + web.path +'" href="javascript:;">点击完善域名</a>'
                              return opt;
                            }
                          }
                        ],
                        data: odata.data
                      })
                      bt.fixed_table('bt_order_list');
                    })
                  })
                }else{
                  robj.append('<div class="alert alert-warning" style="padding:10px">未绑定宝塔账号，请注册绑定，绑定宝塔账号(非论坛账号)可实现一键部署SSL</div>');
                  var datas = [{
                      title: '宝塔账号',
                      name: 'bt_username',
                      value: rdata.email,
                      width: '260px',
                      placeholder: '请输入手机号码'
                    },
                    {
                      title: '密码',
                      type: 'password',
                      name: 'bt_password',
                      value: rdata.email,
                      width: '260px'
                    },
                    {
                      title: ' ',
                      items: [{
                          text: '登录',
                          name: 'btn_ssl_login',
                          type: 'button',
                          callback: function (sdata) {
                            bt.pub.login_btname(sdata.bt_username, sdata.bt_password, function (ret) {
                              if (ret.status) site.reload(7);
                            })
                          }
                        },
                        {
                          text: '注册宝塔账号',
                          name: 'bt_register',
                          type: 'button',
                          callback: function (sdata) {
                            window.open('https://www.bt.cn/register.html')
                          }
                        }
                      ]
                    }
                  ]
                  for (var i = 0; i < datas.length; i++) {
                    var _form_data = bt.render_form_line(datas[i]);
                    robj.append(_form_data.html);
                    bt.render_clicks(_form_data.clicks);
                  }
                  robj.append(bt.render_help(['宝塔SSL证书为亚洲诚信证书，需要实名认证才能申请使用', '已有宝塔账号请登录绑定']));
                }
              })

            }
          },
          {
            title: "关闭",
            callback: function (robj) {
              if (rdata.type == -1) {
                robj.html("<div class='mtb15' style='line-height:30px'>" + lan.site.ssl_help_1 + "</div>");
                return;
              };
              var txt = '';
              switch (rdata.type) {
                case 1:
                  txt = "Let's Encrypt";
                  break;
                case 0:
                  txt = '其他证书';
                  break;
                case 3:
                  txt = 'Comodo Positive';
                  break;
                case 2:
                  txt = lan.site.bt_ssl;
                  break;
              }
              $(".tab-con").html("<div class='line mtb15'>" + lan.get('ssl_enable', [txt]) + "</div><div class='line mtb15'><button class='btn btn-success btn-sm' onclick=\"site.ssl.set_ssl_status('CloseSSLConf','" + web.name + "')\">" + lan.site.ssl_close + "</button></div>");

            }
          },
          {
            title: "证书夹",
            callback: function (robj) {
              robj.html("<div class='divtable' style='height:550px'><table id='cer_list_table' class='table table-hover'></table></div>");
              bt.site.get_cer_list(function (rdata) {
                bt.render({
                  table: '#cer_list_table',
                  columns: [{
                      field: 'subject',
                      title: '域名',
                      templet: function (item) {
                        return item.dns.join('<br>')
                      }
                    },
                    {
                      field: 'notAfter',
                      width: '83px',
                      title: '到期时间'
                    },
                    {
                      field: 'issuer',
                      width: '150px',
                      title: '品牌'
                    },
                    {
                      field: 'opt',
                      width: '75px',
                      align: 'right',
                      title: '操作',
                      templet: function (item) {
                        var server_type = bt.get_cookie("serverType")
                        var opt = ''
                        console.log(item.type, server_type)
                        if ((item.type == 'pfx' && server_type == 'iis') || (item.type == 'pem' && server_type != 'iis')) {
                          opt += '<a class="btlink" onclick="bt.site.set_cert_ssl(\'' + item.subject + '\',\'' + web.name + '\',function(rdata){if(rdata.status){site.ssl.reload();}})" href="javascript:;">部署</a> |'
                        }

                        opt += '<a class="btlink" onclick="bt.site.remove_cert_ssl(\'' + item.subject + '\',function(rdata){if(rdata.status){site.ssl.reload();}})" href="javascript:;">删除</a>'
                        return opt;
                      }
                    }
                  ],
                  data: rdata
                })

                robj.append(bt.render_help(['证书夹部署Let\'s Encrypt不具备自动续签功能']));
              })
            }
          },
          {
            title: "IIS证书",
            callback: function (robj) {
              var loading = bt.load()
              robj.append("<div id='ssl_domain_list_panel' class=\"divtable mtb15 table-fixed-box\" style=\"max-height:500px;overflow-y: auto;\"><table id='ssl_domain_list' class='table table-hover'></table></div>")
              bt.send("get_iis_ssl_bydomain", "site/get_iis_ssl_bydomain", {
                siteName: web.name
              }, function (res) {
                loading.close();
                if (res.status == false) {
                  bt.msg(res)
                  return
                }
                var _tab = bt.render({
                  table: '#ssl_domain_list',
                  columns: [{
                      field: 'name',
                      title: '网站域名'
                    },
                    {
                      field: 'subject',
                      title: '证书域名',
                      templet: function (item) {
                        if (item.status) {
                          return item.cert.dns.join('<br>')
                        }
                        return '--'
                      }
                    },
                    {
                      field: 'notAfter',
                      width: '83px',
                      title: '到期时间',
                      templet: function (item) {
                        if (item.status) {
                          return item.cert.notAfter
                        }
                        return '--'
                      }
                    },
                    {
                      field: 'status',
                      width: '150px',
                      title: '部署状态',
                      templet: function (item) {
                        var msg = "";
                        if (item.status == true) {
                          msg = "<span>已部署";
                          if ($.inArray(item.name, item.cert.dns) >= 0) {
                            msg += "</span>";
                          } else {
                            var is_check = false
                            for (var i = 0; i < item.cert.dns; i++) {
                              if (item.cert.dns[i].indexOf('*') >= 0) {
                                if (item.name.indexOf(item.cert.dns[i].replace("*")) >= 0) {
                                  is_check = true;
                                  break;
                                }
                              }
                            }
                            if (!is_check) {
                              msg += ' <span style="color:red">[证书不匹配]</span>';
                            } else {
                              msg += "</span>"
                            }
                          }
                        } else {
                          msg = "<span>未部署</span>";
                        }
                        return msg;
                      }
                    },
                    {
                      field: 'name',
                      align: "right",
                      title: '操作',
                      width: 60,
                      templet: function (item) {
                        return '<a class="btlink" href="javascript:;" onclick="site.edit.set_iis_domain_ssl(\'' + web.name + '\',this)">部署</a> ';
                      }
                    }
                  ],
                  data: res
                })
                robj.append(bt.render_help(['IIS默认一个网站部署一个证书，如果需要给每个域名部署证书，请阅读 <a href="https://www.bt.cn/bbs/thread-35492-1-1.html" class="btlink" target="_blank">[帮助]</a>。', '证书不匹配：表示证书域名列表不包括此域名，需要自行设置有效的域名']));
              })
            }
          }
        ]
        bt.render_tab('ssl_tabs', _tabs);

        $('#ssl_tabs').append('<div class="ss-text pull-right mr30" style="position: relative;top:-4px"><em>强制HTTPS</em><div class="ssh-item"><input class="btswitch btswitch-ios" id="toHttps" type="checkbox"><label class="btswitch-btn" for="toHttps"></label></div></div>');
        $("#toHttps").attr('checked', rdata.httpTohttps);
        $('#toHttps').click(function (sdata) {
          var isHttps = $("#toHttps").attr('checked');
          if (isHttps) {
            layer.confirm('关闭强制HTTPS后需要清空浏览器缓存才能看到效果,继续吗?', {
              icon: 3,
              title: "关闭强制HTTPS"
            }, function () {
              bt.site.close_http_to_https(web.name, function () {
                site.reload(7);
              })
            });
          } else {
            if (rdata.status == false) {
              bt.msg({
                status: false,
                msg: '请先部署SSL证书，否则无法强制跳转HTTPS.'
              })
              return;
            }
            bt.site.set_http_to_https(web.name, function (res) {

              site.edit.show_rule_msg("强制HTTPS", res);
              if (!res.status) {
                $("#toHttps").attr('checked', rdata.httpTohttps);
              }
            })
          }
        })
        switch (rdata.type) {
          case 0: // 其他证书
            $('#ssl_tabs span:eq(2)').trigger('click');
            break;
          case 1: //  Let's Encrypt
            $('#ssl_tabs span:eq(1)').trigger('click');
            break;
          case 2: // 宝塔证书
            $('#ssl_tabs span:eq(3)').trigger('click');
            break;
          default: // 商业证书或未设置证书
            $('#ssl_tabs span:eq(0)').trigger('click');
            break;
        }

      })
    },
    set_iis_domain_ssl: function (siteName, obj) {
      var loading = bt.load()
      bt.send("get_iis_ssl_file_list", "site/get_iis_ssl_file_list", {
        siteName: siteName
      }, function (res) {
        loading.close();
        if (res.status == false) {
          bt.msg(res)
          return
        }
        var _domain = $(obj).parents('tr').data('item');
        site.ssl.my_select_domain_ssl_index = layer.open({
          type: 1,
          area: ['550px', '550px'],
          title: '部署域名【' + _domain.name + '】SSL证书',
          closeBtn: 2,
          shift: 0,
          content: "<div class=\"divtable pd20 mtb15 table-fixed-box\" style=\"max-height:500px;overflow-y: auto;\"><table id='ssl_select_list' class='table table-hover'></table></div>",
          success: function () {
            var _tab = bt.render({
              table: '#ssl_select_list',
              columns: [{
                  field: 'subject',
                  title: '证书域名',
                  templet: function (item) {
                    return item.dns.join('<br>')
                  }
                },
                {
                  field: 'notAfter',
                  width: '83px',
                  title: '到期时间'
                },
                {
                  field: 'issuer',
                  width: '130px',
                  title: '品牌'
                },
                {
                  field: 'name',
                  align: "right",
                  title: '操作',
                  width: 60,
                  templet: function (item) {
                    return '<a class="btlink" href="javascript:;" onclick="site.edit.set_domain_iis_byfile(\'' + _domain.name + '\',\'' + item.path + '\')" >选择</a> ';
                  }
                }
              ],
              data: res
            })

          }
        })
      })
    },
    set_domain_iis_byfile: function (domain, path, password) {
      var loading = bt.load("正在部署【" + domain + "】证书...");
      bt.send("set_domain_iis_byfile", "site/set_domain_iis_byfile", {
        domain: domain,
        path: path,
        password: password
      }, function (res) {
        loading.close();

        if (res.msg.indexOf('password') >= 0) {
          var index = layer.open({
            type: 1,
            skin: 'demo-class',
            area: '350px',
            title: '填写证书密码',
            closeBtn: 2,
            shift: 5,
            shadeClose: false,
            content: "<div class='bt-form pd20 pb70' >\
							        <div class='line'>\
							        <span class='tname'>证书密码:</span><div class='info-r '><input  type='text' value='bt.cn' class='bt-input-text new_password' /></div>\
							        </div>\
							        <ul class='help-info-text c7'>\
								        <li>在此处填写pfx证书密码!</li>\
								        <li>宝塔证书默认密码bt.cn,其他证书咨询证书提供商!</li>\
							        </ul>\
					                <div class='bt-form-submit-btn'>\
								        <button type='button' class='btn btn-danger btn-sm btn-title' onclick='layer.closeAll()'>取消</button>\
						                <button type='button' class='btn btn-success btn-sm btn-title btnOtherSSL' >提交</button>\
					                </div>\
					                </div>",
            success: function () {
              $(".btnOtherSSL").click(function () {
                site.edit.set_domain_iis_byfile(domain, path, $(".new_password").val())
                layer.close(index);
              })
            }

          });
        } else {
          if (res.status) {
            if (site.ssl.my_select_domain_ssl_index) {
              layer.close(site.ssl.my_select_domain_ssl_index);
            }
            site.ssl.reload()
          }
          bt.msg(res);
        }
      })
    },
    set_php_version: function (web) {
      var loadT = bt.load();
      bt.site.get_site_phpversion(web.name, function (sdata) {
        if (sdata.status === false) {
          bt.msg(sdata);
          return;
        }
        bt.site.get_all_phpversion(function (vdata) {
          loadT.close();
          var versions = [];
          for (var j = vdata.length - 1; j >= 0; j--) {
            var o = vdata[j];
            o.value = o.version;
            o.title = o.name;
            versions.push(o);
          }
          var data = {
            items: [{
                title: 'PHP版本',
                name: 'versions',
                value: sdata.phpversion,
                type: 'select',
                items: versions
              },
              {
                text: '切换',
                name: 'btn_change_phpversion',
                type: 'button',
                callback: function (pdata) {
                  bt.site.set_phpversion(web.name, pdata.versions, function (ret) {
                    if (ret.status) site.reload()
                    bt.msg(ret);
                  })
                }
              }
            ]
          }
          var _form_data = bt.render_form_line(data);
          var _html = $(_form_data.html);
          _html.append(bt.render_help(['请根据您的程序需求选择版本', '若非必要,请尽量不要使用PHP5.2,这会降低您的服务器安全性；', 'PHP7不支持mysql扩展，默认安装mysqli以及mysql-pdo。']));
          $('#webedit-con').append(_html);
          bt.render_clicks(_form_data.clicks);
        })
      })
    },
    templet_301: function (web, obj) {
      var is_create = false
      if (obj === false) {
        is_create = true
        obj = {
          redirectname: (new Date()).valueOf(),
          tourl: 'http://',
          redirectdomain: [],
          redirectpath: '',
          redirecttype: '',
          domainorpath: 'domain',
          type: 1,
          holdpath: 1
        }
      }
      console.log(obj);
      var helps = [
        '重定向类型：表示访问选择的“域名”或输入的“路径”时将会重定向到指定URL',
        '目标URL：可以填写你需要重定向到的站点，目标URL必须为可正常访问的URL，否则将返回错误',
        '重定向方式：使用301表示永久重定向，使用302表示临时重定向',
        '保留URI参数：表示重定向后访问的URL是否带有子路径或参数如设置访问http://b.com 重定向到http://a.com',
        '保留URI参数： http://b.com/1.html ---> http://a.com/1.html',
        '不保留URI参数：http://b.com/1.html ---> http://a.com',
        '路径重定向：将app目录重定向到www.bt.cn/app目录格式为 app/ ---> http://www.bt.cn'
      ];
      bt.site.get_domains(web.id, function (rdata) {
        var domains = [];
        for (var i = 0; i < rdata.length; i++) {
          var val = rdata[i].name;
          if (rdata[i].port != 80) val += ':' + rdata[i].port;
          domains.push({
            title: val,
            value: val
          });
        }

        var form_data = {
          title: is_create ? '创建重定向' : '修改重定向[' + obj.redirectname + ']',
          area: ['650px', '430px'],
          skin: 'site-301-form',
          list: [{
              class: 'btswitch-line ',
              items: [{
                  title: '开启重定向  ',
                  name: 'type',
                  value: obj.type == 1 ? true : false,
                  type: 'btswitch'
                },
                {
                  title: '保留URI参数  ',
                  name: 'holdpath',
                  value: obj.holdpath == 1 ? true : false,
                  type: 'btswitch'
                }
              ]
            },
            {
              title: '重定向名称  ',
              value: obj.redirectname,
              name: 'redirectname',
              width: '300px',
              hide: true
            },
            {
              items: [{
                  title: '重定向类型  ',
                  name: 'domainorpath',
                  value: obj.domainorpath,
                  type: 'select',
                  items: [{
                      title: '域名',
                      value: 'domain'
                    },
                    {
                      title: '路径',
                      value: 'path'
                    },
                  ],
                  callback: function (sobj) {
                    var subid = sobj.attr('name') + '_subid';
                    $('#' + subid).remove();
                    if (sobj.val() == 'domain') {
                      var item = {
                        items: [{
                            title: '重定向域名 ',
                            name: 'redirectdomain',
                            width: '173px',
                            type: 'select',
                            class: 'selectpicker',
                            items: domains
                          },
                          {
                            title: '目标URL  ',
                            name: 'tourl',
                            value: obj.tourl,
                            width: '173px'
                          },
                        ]
                      }
                      var _tr = bt.render_form_line(item)
                      sobj.parents('div.line').append('<div class="line" id=' + subid + '>' + _tr.html + '</div>');
                      site.edit.render_sel('redirectdomain', obj.redirectdomain);
                    } else {
                      var item = {
                        items: [{
                            title: '重定向路径  ',
                            name: 'redirectpath',
                            value: obj.redirectpath,
                            width: '173px'
                          },
                          {
                            title: '目标URL  ',
                            name: 'tourl',
                            value: obj.tourl,
                            width: '173px'
                          },
                        ]
                      }
                      var _tr = bt.render_form_line(item)
                      sobj.parents('div.line').append('<div class="line" id=' + subid + '>' + _tr.html + '</div>');
                    }
                  }
                },
                {
                  title: '重定向方式 ',
                  name: 'redirecttype',
                  value: obj.redirecttype,
                  type: 'select',
                  items: [{
                      title: '301',
                      value: '301'
                    },
                    {
                      title: '302',
                      value: '302'
                    },
                  ]
                }
              ]
            }
          ],
          btns: [
            bt.form.btn.close(),
            bt.form.btn.submit('提交', function (rdata, form) {
              if (!rdata.hasOwnProperty("redirectpath")) {
                rdata['redirectpath'] = '';
              }
              rdata.type = rdata.type ? 1 : 0;
              rdata.holdpath = rdata.holdpath ? 1 : 0;

              rdata['sitename'] = web.name;
              rdata['redirectdomain'] = JSON.stringify($('.selectpicker').val() || []);
              if (is_create) {
                bt.site.create_redirect(rdata, function (rdata) {
                  form.close();
                  site.edit.show_rule_msg("添加重定向", rdata);
                });
              } else {
                bt.site.modify_redirect(rdata, function (rdata) {
                  form.close();
                  site.edit.show_rule_msg("修改重定向", rdata)
                });
              }
            })
          ],
          success: function () {
            $('.site-301-form').css('top', (($(window)[0].innerHeight - $('.site-301-form').height()) / 2) + 'px');
          }
        }
        bt.render_form(form_data);
        var h = $(bt.render_help(helps));
        h.css({
          'bottom': '60px'
        })

        $('.' + form_data.skin + ' .bt-form').append(h);
        setTimeout(function () {
          $("select[name='domainorpath']").trigger("change");
        }, 100)

      });
    },
    edit_redirect: function (obj, name) {
      var item = $(obj).parents('tr').data('item');
      if (item[name]) {
        item[name] = 0;
      } else {
        item[name] = 1
      }
      item['redirectdomain'] = JSON.stringify(item['redirectdomain'] || []);

      bt.site.modify_redirect(item, function (rdata) {
        site.edit.show_rule_msg("修改重定向", rdata)
      });
    },
    template_Dir: function (id, type, obj) {
      if (type) {
        obj = {
          "name": "",
          "sitedir": "",
          "username": "",
          "password": ""
        };
      } else {
        obj = {
          "name": obj.name,
          "sitedir": obj.site_dir,
          "username": obj.username,
          "password": obj.password
        };
      }
      var form_directory = bt.open({
        type: 1,
        skin: 'demo-class',
        area: '550px',
        title: type ? '添加目录保护' : '修改目录目录',
        closeBtn: 2,
        shift: 5,
        shadeClose: false,
        content: "<form id='form_dir' class='divtable pd15' style='padding: 40px 0 90px 60px'>" +
          "<div class='line'>" +
          "<span class='tname'>名称</span>" +
          "<div class='info-r ml0'><input name='dir_name' class='bt-input-text mr10' type='text' style='width:270px' value='" + obj.name + "'>" +
          "</div></div>" +
          "<div class='line'>" +
          "<span class='tname'>保护的目录</span>" +
          "<div class='info-r ml0'><input name='dir_sitedir' placeholder='输入需要保护的目录，如：/text/' class='bt-input-text mr10' type='text' style='width:270px' value='" + obj.sitedir + "'>" +
          "</div></div>" +
          "<div class='line'>" +
          "<span class='tname'>用户名</span>" +
          "<div class='info-r ml0'><input name='dir_username' AUTOCOMPLETE='off' class='bt-input-text mr10' type='text' style='width:270px' value='" + obj.username + "'>" +
          "</div></div>" +
          "<div class='line'>" +
          "<span class='tname'>密码</span>" +
          "<div class='info-r ml0'><input name='dir_password' AUTOCOMPLETE='off' class='bt-input-text mr10' type='password' style='width:270px' value='" + obj.password + "'>" +
          "</div></div>" +
          "<ul class='help-info-text c7 plr20'>" +
          "<li>目录设置保护后，访问时需要输入账号密码才能访问</li>" +
          "<li>例如我设置了保护目录 /test/ ,那我访问 http://aaa.com/test/ 是就要输入账号密码才能访问</li>" +
          "</ul>" +
          "<div class='bt-form-submit-btn'><button type='button' class='btn btn-sm btn-danger btn-colse-guard'>关闭</button><button type='button' class='btn btn-sm btn-success btn-submit-guard'>" + (type ? '提交' : '保存') + "</button></div></form>"
      });
      $('.btn-colse-guard').click(function () {
        form_directory.close();
      });
      $('.btn-submit-guard').click(function () {
        var guardData = {};
        guardData['id'] = id;
        guardData['name'] = $('input[name="dir_name"]').val();
        guardData['site_dir'] = $('input[name="dir_sitedir"]').val();
        guardData['username'] = $('input[name="dir_username"]').val();
        guardData['password'] = $('input[name="dir_password"]').val();
        if (type) {
          bt.site.create_dir_guard(guardData, function (rdata) {
            if (rdata.status) {
              form_directory.close();
              site.reload()
            }
            bt.msg(rdata);
          });
        } else {
          bt.site.edit_dir_account(guardData, function (rdata) {
            if (rdata.status) {
              form_directory.close();
              site.reload()
            }
            bt.msg(rdata);
          });
        }
      });
      setTimeout(function () {
        if (!type) {
          $('input[name="dir_name"]').attr('disabled', 'disabled');
          $('input[name="dir_sitedir"]').attr('disabled', 'disabled');
        }
      }, 500)

    },
    set_301: function (web) {
      bt.site.get_redirect_list(web.name, function (rdata) {
        if (rdata.status === false) {
          bt.msg(rdata);
          return
        }
        var datas = {
          items: [{
            name: 'add_proxy',
            text: '添加重定向',
            type: 'button',
            callback: function (data) {
              site.edit.templet_301(web, false)
            }
          }]
        }
        var form_line = bt.render_form_line(datas);
        $('#webedit-con').append(form_line.html);
        bt.render_clicks(form_line.clicks);
        $('#webedit-con').addClass('divtable').append('<table id="proxy_list" class="table table-hover"></table>');
        setTimeout(function () {
          var _tab = bt.render({
            table: '#proxy_list',
            columns: [{
                field: '',
                title: '重定向类型',
                templet: function (item) {
                  var conter = '';
                  if (item.domainorpath == 'path') {
                    conter = item.redirectpath;
                  } else {
                    conter = item.redirectdomain ? item.redirectdomain.join('、') : '空'
                  }
                  return '<span style="width:100px;" title="' + conter + '">' + conter + '</span>';
                }
              },
              {
                field: 'redirecttype',
                title: '重定向方式'
              },
              {
                field: 'holdpath',
                index: true,
                title: '保留路径',
                templet: function (item) {
                  return '<a href="javascript:;" onclick="site.edit.edit_redirect(this,\'holdpath\')" class="btlink set_path_state" style="display:" data-stuats="' + (item.holdpath == 1 ? 0 : 1) + '">' + (item.holdpath == 1 ? '<span style="color:#20a53a;" class="set_path_state">开启</span>' : '<span style="color:red;" class="set_path_state">关闭</span>') + '</a>';
                }
              },
              {
                field: 'type',
                title: '状态',
                index: true,
                templet: function (item) {
                  return '<a href="javascript:;" onclick="site.edit.edit_redirect(this,\'type\')" class="btlink set_type_state" style="display:" data-stuats="' + (item.type == 1 ? 0 : 1) + '">' + (item.type == 1 ? '<span style="color:#20a53a;">运行中</span><span style="color:#5CB85C" class="glyphicon glyphicon-play"></span>' : '<span style="color:red;">已暂停</span><span style="color:red" class="glyphicon glyphicon-pause"></span>') + '</a>'
                }
              },
              {
                field: '',
                title: '操作',
                align: 'right',
                index: true,
                templet: function (item) {
                  var redirectname = item.redirectname;
                  var sitename = item.sitename;
                  var open_file = '';
                  if (bt.get_cookie("serverType") != 'iis') {
                    open_file = '<a class="btlink open_config_file" href="javascript:;">配置文件</a> | '
                  }
                  var conter = open_file + ' <a class="btlink edit_redirect"  href="javascript:;">编辑</a> | <a class="btlink" onclick="bt.site.remove_redirect(\'' + sitename + '\',\'' + redirectname + '\',function(rdata){if(rdata.status)site.reload(10)})" href="javascript:;">删除</a>';
                  return conter
                }
              }
            ],
            data: rdata
          });

          $('.edit_redirect').click(function () {
            var item = $(this).parents('tr').data('item');
            site.edit.templet_301(web, item);
          });
          $('.open_config_file').click(function () {
            var item = $(this).parents('tr').data('item');
            var sitename = web.name;
            var redirectname = item.redirectname;
            var redirect_config = '';
            bt.site.get_redirect_config({
              sitename: sitename,
              redirectname: redirectname,
              webserver: bt.get_cookie('serverType')
            }, function (rdata) {
              if (typeof rdata == 'object' && rdata.constructor == Array) {
                if (!rdata[0].status) bt.msg(rdata)
              } else {
                if (rdata.status == false) bt.msg(rdata)
              }
              var datas = [{
                  items: [{
                    name: 'redirect_configs',
                    type: 'textarea',
                    value: rdata[0].data,
                    widht: '340px',
                    height: '200px'
                  }]
                },
                {
                  name: 'btn_config_submit',
                  text: '保存',
                  type: 'button',
                  callback: function (ddata) {
                    bt.site.save_redirect_config({
                      path: rdata[1],
                      data: editor.getValue(),
                      encoding: rdata[0].encoding
                    }, function (ret) {
                      if (ret.status) {
                        site.reload(11);
                        redirect_config.close();
                      }
                      bt.msg(ret);
                    })
                  }
                }
              ]
              redirect_config = bt.open({
                type: 1,
                area: ['550px', '550px'],
                title: '编辑配置文件[' + redirectname + ']',
                closeBtn: 2,
                shift: 0,
                content: "<div class='bt-form'><div id='redirect_config_con' class='pd15'></div></div>"
              })
              var robj = $('#redirect_config_con');
              for (var i = 0; i < datas.length; i++) {
                var _form_data = bt.render_form_line(datas[i]);
                robj.append(_form_data.html);
                bt.render_clicks(_form_data.clicks);
              }
              robj.append(bt.render_help(['此处为重定向的配置文件，若您不了解配置规则,请勿随意修改。']));
              $('textarea.redirect_configs').attr('id', 'configBody');
              var editor = CodeMirror.fromTextArea(document.getElementById("configBody"), {
                extraKeys: {
                  "Ctrl-Space": "autocomplete"
                },
                lineNumbers: true,
                matchBrackets: true
              });
              $(".CodeMirror-scroll").css({
                "height": "350px",
                "margin": 0,
                "padding": 0
              });
              setTimeout(function () {
                editor.refresh();
              }, 250);
            });
          });
        }, 100);
      });
    },
    render_sel: function (name, data) {
      var _domain_sel = $("select[name='" + name + "']");
      _domain_sel.attr('data-actions-box', true);
      _domain_sel.attr('data-size', 5);
      _domain_sel.attr('multiple', true);
      _domain_sel.attr('data-live-search', false);
      _domain_sel.addClass('selectpicker show-tick form-control');
      _domain_sel.selectpicker({
        'noneSelectedText': '请选择站点...',
        'selectAllText': '全选',
        'deselectAllText': '取消全选'
      });
      _domain_sel.parents('.bootstrap-select').removeClass('bt-input-text').attr('style', 'float: inherit!important')
      if (typeof data != 'undefined') _domain_sel.selectpicker('val', data);
    },
    templet_proxy: function (web, obj) {
      var is_create = false
      if (obj === false) {
        is_create = true
        obj = {
          proxyname: (new Date()).valueOf(),
          tourl: 'http://',
          proxydomains: [],
          to_domian: '$host',
          open: 1,
          cache_open: 1,
          path_open: 0,
          root_path: '/',
        }
      }
      if (!obj.hasOwnProperty("sub1")) {
        obj['sub1'] = '';
        obj['sub2'] = '';
      }
      var helps = [
        '代理目录：访问这个目录时将会把目标URL的内容返回并显示(需要开启高级功能)',
        '目标URL：可以填写你需要代理的站点，目标URL必须为可正常访问的URL，否则将返回错误',
        '发送域名：将域名添加到请求头传递到代理服务器，默认为目标URL域名，若设置不当可能导致无法正常运行',
        '内容替换：只能在使用nginx时提供，多个内容用逗号分开，如sub1,sub2替换为str1,str2',
      ];
      bt.site.get_domains(web.id, function (rdata) {
        var domains = [];
        for (var i = 0; i < rdata.length; i++) {
          var val = rdata[i].name;
          if (rdata[i].port != 80) val += ':' + rdata[i].port;
          domains.push({
            title: val,
            value: val
          });
        }
        var form_data = {
          title: is_create ? '创建反向代理' : '修改反向代理[' + obj.proxyname + ']',
          area: ['650px', '400px'],
          skin: 'site-proxy-form',
          list: [{
              class: 'btswitch-line ',
              items: [{
                  title: '开启代理  ',
                  name: 'open',
                  value: obj.open == 1 ? true : false,
                  type: 'btswitch'
                },
                {
                  title: '开启缓存  ',
                  name: 'cache_open',
                  hide: bt.get_cookie('serverType') == 'iis' ? false : true,
                  value: obj.cache_open == 1 ? true : false,
                  type: 'btswitch'
                },
                {
                  title: '高级功能  ',
                  name: 'path_open',
                  value: obj.path_open == 1 ? true : false,
                  type: 'btswitch'
                }
              ]
            },
            {
              items: [{
                title: '代理名称   ',
                disabled: is_create ? false : true,
                width: '200px',
                value: obj.proxyname,
                name: 'proxyname'
              }]
            },
            {
              class: 'root_path-line',
              items: [{
                title: '代理路径   ',
                width: '200px',
                value: obj.root_path,
                name: 'root_path'
              }]
            },
            {
              items: [{
                title: '请求域名   ',
                hide: bt.get_cookie('serverType') == 'iis' ? false : true,
                name: 'proxydomains',
                type: 'select',
                class: 'selectpicker',
                items: domains
              }]
            },
            {
              items: [{
                  title: '目标URL   ',
                  name: 'tourl',
                  value: obj.tourl,
                  width: '200px',
                  callback: function (robj) {
                    var val = $(robj).val(),
                      ip_reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
                    val = val.replace(/^http[s]?:\/\//, '');
                    val = val.replace(/:([0-9]*)$/, '');
                    if (ip_reg.test(val) || bt.get_cookie('serverType') == 'iis') {
                      $("input[name='to_domian']").val('$host');
                    } else {
                      $("input[name='to_domian']").val(val);
                    }
                  }
                },
                {
                  title: '发送域名   ',
                  name: 'to_domian',
                  value: obj.to_domian,
                  width: '200px'
                },
              ]
            },
            {
              hide: bt.get_cookie('serverType') == 'nginx' ? false : true,
              items: [{
                  title: '替换内容   ',
                  name: 'sub1',
                  value: obj.sub1,
                  width: '200px'
                },
                {
                  title: '&nbsp;&nbsp;&nbsp;替换为   ',
                  name: 'sub2',
                  value: obj.sub2,
                  width: '200px'
                },
              ]
            }
          ],
          btns: [
            bt.form.btn.close(),
            bt.form.btn.submit('提交', function (rdata, load) {
              if (rdata.sub1.split(',').length != rdata.sub2.split(',').length) {
                bt.msg({
                  status: false,
                  msg: '替换内容个数必须与替换后个数量相等.'
                });
                return;
              }
              rdata.open = rdata.open ? 1 : 0;
              rdata.cache_open = obj['cache_open']
              rdata.path_open = rdata.path_open ? 1 : 0;
              rdata['sitename'] = web.name;
              rdata['proxydomains'] = JSON.stringify($('.selectpicker').val() || []);
              if (is_create) {
                bt.site.create_proxy(rdata, function (ret) {
                  site.edit.show_rule_msg("添加反向代理", ret)
                });
              } else {
                bt.site.modify_proxy(rdata, function (ret) {
                  site.edit.show_rule_msg("修改反向代理", ret)
                });
              }
            })
          ],
          sucess: function () {

          }
        }
        bt.render_form(form_data);
        var h = $(bt.render_help(helps));
        h.css({
          'bottom': '60px'
        })

        $('.' + form_data.skin + ' .bt-form').append(h);
        site.edit.render_sel('proxydomains', obj.proxydomains);
        $("#path_open").change(function () {
          var robj = $('.root_path-line');
          if ($(this).prop('checked')) {
            robj.show();
          } else {
            robj.hide();
          }
        })
        $("#path_open").trigger("change");
        $('.proxydomains').selectpicker('val', obj.proxydomains);
      });
    },
    edit_proxy: function (obj, name) {
      var item = $(obj).parents('tr').data('item');
      if (item[name]) {
        item[name] = 0;
      } else {
        item[name] = 1
      }
      item['proxydomains'] = JSON.stringify(item['proxydomains'] || []);

      bt.site.modify_proxy(item, function (ret) {
        site.edit.show_rule_msg("修改反向代理", ret)
      });
    },
    show_rule_msg: function (title, ret) {
      if (ret.status) {
        site.reload();
      }
      if (ret.hasOwnProperty('xml')) {
        site.reload();
        layer.open({
          type: 1,
          title: title,
          area: ['650px', '420px'],
          closeBtn: 2,
          shadeClose: false,
          content: '<div class="redireSiteTips pd15 pb70">\
									<div class="redireTipsHead">\
										<div class="info-title-tips" style="line-height: 27px;padding: 5px 10px;">\
											<p>\
												<span class="glyphicon glyphicon-alert" style="color: #f39c12; margin-right: 10px;"></span>\
												<span style="line-height:22px">' + ret.msg + '，<a class="btlink" href="https://www.bt.cn/bbs/thread-51777-1-1.html" target="_blank">详细教程>></a></span>\
											</p>\
										</div></div>\
									<div class="redireTipsBody">\
										<textarea class="bt-input-text" style="height: 200px; line-height: 18px; display: none;" id="redireSiteCode"></textarea>\
									</div>\
								</div>\
								<div class="bt-form-submit-btn">\
									<button type="button" class="btn btn-sm btn-success" id="xml-copy">复制</button>\
								</div>',
          success: function (layers, index) {
            $('#xml-copy').click(function () {
              bt.pub.copy_pass(ret.xml)
            })
            $("#redireSiteCode").empty().text(ret.xml);
            $(".CodeMirror").remove();
            var editor = CodeMirror.fromTextArea(document.getElementById("redireSiteCode"), {
              extraKeys: {
                "Ctrl-Space": "autocomplete"
              },
              lineNumbers: true,
              matchBrackets: true,
            });
            editor.focus();
            $(".CodeMirror-scroll").css({
              "height": "200px",
              "margin": 0,
              "padding": 0
            });
          }
        })
        return;
      }
      bt.msg(ret);
    },
    set_proxy: function (web) {
      bt.site.get_proxy_list(web.name, function (rdata) {
        if (rdata.status === false) {
          rdata.time = 0
          bt.msg(rdata);
          return;
        }
        var robj = $('#webedit-con');
        var datas = {
          items: [{
            name: 'add_proxy',
            text: '添加反向代理',
            type: 'button',
            callback: function (data) {
              site.edit.templet_proxy(web, false)
            }
          }]
        }
        var form_line = bt.render_form_line(datas);
        $('#webedit-con').append(form_line.html);
        bt.render_clicks(form_line.clicks);
        $('#webedit-con').addClass('divtable').append('<table id="proxy_list" class="table table-hover"></table>');
        setTimeout(function () {
          var _tab = bt.render({
            table: '#proxy_list',
            columns: [{
                field: 'proxyname',
                title: '名称',
                templet: function (item) {
                  return '<span style="width:70px;" title="' + item.proxyname + '">' + item.proxyname + '</span>';
                }
              },
              {
                field: 'root_path',
                title: '目录'
              },
              {
                field: 'tourl',
                title: '目标url',
                templet: function (item) {
                  return '<span style="width:70px;" title="' + item.tourl + '">' + item.tourl + '</span>';
                }
              },
              {
                field: 'open',
                title: '状态',
                index: true,
                templet: function (item) {
                  return '<a href="javascript:;" onclick="site.edit.edit_proxy(this,\'open\')" class="btlink set_type_state" style="display:" data-stuats="' + (item.open == 1 ? 0 : 1) + '">' + (item.open == 1 ? '<span style="color:#20a53a;">运行中</span><span style="color:#5CB85C" class="glyphicon glyphicon-play"></span>' : '<span style="color:red;">已暂停</span><span style="color:red" class="glyphicon glyphicon-pause"></span>') + '</a>'
                }
              },
              {
                field: 'cache_open',
                title: '缓存',
                index: true,
                templet: function (item) {
                  return '<a href="javascript:;" onclick="site.edit.edit_proxy(this,\'cache_open\')" class="btlink set_type_state" style="display:" data-stuats="' + (item.cache_open == 1 ? 0 : 1) + '">' + (item.cache_open == 1 ? '<span style="color:#20a53a;">开启</span><span style="color:#5CB85C" class="glyphicon glyphicon-play"></span>' : '<span style="color:red;">关闭</span><span style="color:red" class="glyphicon glyphicon-pause"></span>') + '</a>'
                }
              },
              {
                field: '',
                title: '操作',
                width: '150px',
                align: 'right',
                index: true,
                templet: function (item) {
                  var redirectname = item.redirectname;
                  var sitename = item.sitename;
                  var open_file = '';
                  if (bt.get_cookie("serverType") != 'iis') {
                    open_file = '<a class="btlink open_config_file" href="javascript:;">配置文件</a> | '
                  }
                  var conter = open_file + ' <a class="btlink edit_proxy"  href="javascript:;">编辑</a> | <a class="btlink" onclick="bt.site.remove_proxy(\'' + sitename + '\',\'' + item.proxyname + '\',function(rdata){if(rdata.status)site.reload()})" href="javascript:;">删除</a>';
                  return conter
                }
              }
            ],
            data: rdata
          });
          $('.open_config_file').click(function () {
            var item = $(this).parents('tr').data('item');
            var sitename = web.name;
            var proxyname = item.proxyname;

            var proxy_config = '';
            bt.site.get_proxy_config({
              sitename: sitename,
              proxyname: proxyname,
              webserver: bt.get_cookie('serverType')
            }, function (rdata) {
              if (typeof rdata == 'object' && rdata.constructor == Array) {
                if (!rdata[0].status) bt.msg(rdata)
              } else {
                if (rdata.status == false) bt.msg(rdata)
              }
              var datas = [{
                  items: [{
                    name: 'proxy_configs',
                    type: 'textarea',
                    value: rdata[0].data,
                    widht: '340px',
                    height: '200px'
                  }]
                },
                {
                  name: 'btn_config_submit',
                  text: '保存',
                  type: 'button',
                  callback: function (ddata) {
                    bt.site.save_proxy_config({
                      path: rdata[1],
                      data: editor.getValue(),
                      encoding: rdata[0].encoding
                    }, function (ret) {
                      if (ret.status) {
                        site.reload(12);
                        proxy_config.close();
                      }
                      bt.msg(ret);
                    })
                  }
                }
              ]
              proxy_config = bt.open({
                type: 1,
                area: ['550px', '550px'],
                title: '编辑配置文件[' + proxyname + ']',
                closeBtn: 2,
                shift: 0,
                content: "<div class='bt-form'><div id='proxy_config_con' class='pd15'></div></div>"
              })
              var robj = $('#proxy_config_con');
              for (var i = 0; i < datas.length; i++) {
                var _form_data = bt.render_form_line(datas[i]);
                robj.append(_form_data.html);
                bt.render_clicks(_form_data.clicks);
              }
              robj.append(bt.render_help(['此处为该负载均衡的配置文件，若您不了解配置规则,请勿随意修改。']));
              $('textarea.proxy_configs').attr('id', 'configBody');
              var editor = CodeMirror.fromTextArea(document.getElementById("configBody"), {
                extraKeys: {
                  "Ctrl-Space": "autocomplete"
                },
                lineNumbers: true,
                matchBrackets: true
              });
              $(".CodeMirror-scroll").css({
                "height": "350px",
                "margin": 0,
                "padding": 0
              });
              setTimeout(function () {
                editor.refresh();
              }, 250);
            });
          });
          $('.edit_proxy').click(function () {
            var item = $(this).parents('tr').data('item');
            site.edit.templet_proxy(web, item);
          });
        })
      })
    },
    set_security: function (web) {
      var loadT = bt.load();
      bt.site.get_site_security(web.id, web.name, function (rdata) {
        loadT.close();
        if (rdata.status === false) {
          bt.msg(rdata);
          return;
        }
        var robj = $('#webedit-con');
        var datas = [{
            title: 'URL后缀',
            name: 'sec_fix',
            value: rdata.fix,
            type: "textarea",
            disabled: rdata.status,
            width: '360px'
          },
          {
            title: '许可域名',
            name: 'sec_domains',
            type: "textarea",
            value: rdata.domains,
            disabled: rdata.status,
            width: '360px'
          },

          {
            title: ' ',
            class: 'label-input-group',
            items: [{
              text: '启用防盗链',
              name: 'status',
              value: rdata.status,
              type: 'checkbox',
              callback: function (sdata) {
                bt.site.set_site_security(web.id, web.name, sdata.sec_fix, sdata.sec_domains, sdata.status, function (ret) {
                  site.edit.show_rule_msg("修改防盗链", ret)
                })
              }
            }]
          }
        ]
        for (var i = 0; i < datas.length; i++) {
          var _form_data = bt.render_form_line(datas[i]);
          robj.append(_form_data.html);
          bt.render_clicks(_form_data.clicks);
        }
        var helps = ['默认允许资源被直接访问,即不限制HTTP_REFERER为空的请求', '多个URL后缀与域名请使用逗号(,)隔开,如: png,jpeg,zip,js', '当触发防盗链时,将直接返回404状态']
        robj.append(bt.render_help(helps));
      })
    },
    set_tomact: function (web) {
      bt.site.get_site_phpversion(web.name, function (rdata) {
        var robj = $('#webedit-con');
        if (!rdata.tomcatversion) {
          robj.html('<font>' + lan.site.tomcat_err_msg1 + '</font>');
          layer.msg(lan.site.tomcat_err_msg, {
            icon: 2
          });
          return;
        }
        var data = {
          class: 'label-input-group',
          items: [{
            text: lan.site.enable_tomcat,
            name: 'tomcat',
            value: rdata.tomcat == -1 ? false : true,
            type: 'checkbox',
            callback: function (sdata) {
              bt.site.set_tomcat(web.name, function (ret) {
                if (ret.status) site.reload(9)
                bt.msg(ret);
              })
            }
          }]
        }
        var _form_data = bt.render_form_line(data);
        robj.append(_form_data.html);
        bt.render_clicks(_form_data.clicks);
        var helps = [lan.site.tomcat_help1 + ' ' + rdata.tomcatversion + ',' + lan.site.tomcat_help2, lan.site.tomcat_help3, lan.site.tomcat_help4, lan.site.tomcat_help5]
        robj.append(bt.render_help(helps));
      })
    },
    get_site_logs: function (web) {
      bt.site.get_site_logs(web.name, function (rdata) {
        var robj = $('#webedit-con'),
          _logs = '';
        if (rdata.path != '' && rdata.path != undefined) {
          _logs += '<div style="margin-bottom: 5px; position: relative; height:30px;line-height:30px;">日志路径：<a class="btlink" title="打开目录" href="javascript:openPath(\'' + rdata.path + '\');">' + rdata.path + '</a>'
          if (bt.get_cookie('serverType') == 'iis') {
            _logs += '<button style="position: absolute;right:0" onclick="site.edit.check_log_time()" class ="btn btn-success btn-sm btn-title">校对IIS日志时间</button>'
          }
          _logs += "</div>"
          robj.append(_logs)
        }
        var logs = {
          class: 'bt-logs',
          items: [{
            name: 'site_logs',
            height: '530px',
            value: rdata.msg,
            width: '100%',
            type: 'textarea'
          }]
        }
        var _form_data = bt.render_form_line(logs);
        robj.append(_form_data.html);
        bt.render_clicks(_form_data.clicks);
        $('textarea[name="site_logs"]').attr('readonly', true);
      })
    },
    check_log_time: function () {
      bt.confirm({
        msg: "是否立即校对IIS日志时间，校对后日志统一使用北京时间记录？",
        title: '提示'
      }, function () {
        var loading = bt.load()
        bt.send("check_log_time", 'site/check_log_time', {}, function (rdata) {
          loading.close();
          if (rdata.status) {
            site.reload();
          }
          bt.msg(rdata);
        })
      })
    }
  },
  sync_iis: function () {

    bt.confirm({
      msg: "此功能仅用于重装系统后，恢复网站到IIS，是否立即恢复？",
      title: '提示'
    }, function () {
      var arr = []
      $('input[type="checkbox"].check:checked').each(function () {
        var _val = $(this).val();
        if (!isNaN(_val)) arr.push($(this).parents('tr').data('item')['id']);
      })
      if (arr.length > 0) {
        var loading = bt.load()
        bt.send("sync_iis_site", 'site/sync_iis_site', {
          ids: JSON.stringify(arr)
        }, function (rdata) {
          loading.close();
          if (rdata.status) {
            site.reload();
          }
          bt.msg(rdata);
        })
      }
    })

  },
  create_let: function (ddata, callback) {
    bt.site.create_let(ddata, function (ret) {
      if (ret.status) {
        if (callback) {
          callback(ret);
        } else {
          site.ssl.reload();
          bt.msg(ret);
          return;
        }
      } else {
        if (!ret.out) {
          bt.msg(ret);
          return;
        }
        var data = "<p>" + ret.msg + "</p><hr />"
        if (ret.err[0].length > 10) data += '<p style="color:red;">' + ret.err[0].replace(/\n/g, '<br>') + '</p>';
        if (ret.err[1].length > 10) data += '<p style="color:red;">' + ret.err[1].replace(/\n/g, '<br>') + '</p>';

        layer.msg(data, {
          icon: 2,
          area: '500px',
          time: 0,
          shade: 0.3,
          shadeClose: true
        });
      }
    })
  },
  upload_pfx: function () {
    var path = setup_path + "/temp/ssl/";
    bt_upload_file.open(path, ".pfx", ' <span style="color:red;">请上传pfx文件</span>', function (path) {
      site.reload();
    });
    return;

    var path = setup_path + "/temp/ssl/";
    var index = layer.open({
      type: 1,
      closeBtn: 2,
      title: '上传IIS证书文件 --- <span style="color:red;">请上传pfx文件</span>',
      area: ['500px', '500px'],
      shadeClose: false,
      content: '<div class="fileUploadDiv">\
                            <input type="hidden" id="input-val" value="' + path + '" />\
				            <input type="file" id="file_input" multiple="true" autocomplete="off" />\
				            <button type="button"  id="opt" autocomplete="off">添加文件</button>\
				            <button type="button" id="up" autocomplete="off" >开始上传</button>\
				            <span id="totalProgress" style="position: absolute;top: 7px;right: 147px;"></span>\
                            <input type="hidden" id ="fileCodeing" value ="utf-8" />\
				            <button type="button" id="filesClose" autocomplete="off">关闭</button>\
				            <ul id="up_box"></ul>\
                        </div>'
    });
    $("#filesClose").click(function () {
      layer.close(index);
      site.reload();
      setTimeout(site.ssl.reload(), 200)
    });
    UploadStart(false);
  },
  reload: function (index) {
    if (index == undefined) index = 0
    var _sel = $('.site-menu p.bgw');
    if (_sel.length > 0) {
      if (_sel.index() == 0) {
        _sel = $('.site-menu p:eq(' + index + ')');
      }
    } else {
      _sel = $('.site-menu p:eq(' + index + ')');
    }

    _sel.trigger('click');
  },
  //拆分多个配置
  set_iis_multiple: function (siteName) {

    bt.confirm({
      msg: "是否确定执行自动解析？",
      title: '提示'
    }, function () {
      var loading = bt.load()
      bt.send("set_iis_multiple", 'site/set_iis_multiple', {
        siteName: siteName
      }, function (rdata) {
        loading.close();
        if (rdata.status) {
          site.reload();
        }
        bt.msg(rdata);
      })
    })

  },
  plugin_firewall: function () {
    var typename = bt.get_cookie('serverType');
    var name = 'waf_' + typename;

    bt.plugin.get_plugin_byhtml(name, function (rhtml) {
      if (rhtml.status === false) return;

      var list = rhtml.split('<script type="javascript/text">');
      if (list.length > 1) {
        rcode = rhtml.split('<script type="javascript/text">')[1].replace("<\/script>", "");
      } else {
        list = rhtml.split('<script type="text/javascript">');
        rcode = rhtml.split('<script type="text/javascript">')[1].replace("<\/script>", "");
      }
      rcss = rhtml.split('<style>')[1].split('</style>')[0];
      $("body").append('<div style="display:none"><style>' + rcss + '</style><script type="javascript/text">' + rcode + '<\/script></div>');
      setTimeout(function () {
        if (!!(window.attachEvent && !window.opera)) {
          execScript(rcode);
        } else {
          window.eval(rcode);
        }
      }, 200)
    })
  },

  select_site_txt: function (box) {
    layer.open({
      type: 1,
      closeBtn: 2,
      title: '自定义域名',
      area: '600px',
      btn: ['确认', '取消'],
      content: '<div class="pd20"><div class="line "><span class="tname">自定义域名</span><div class="info-r "><input  name="site_name" placeholder="请输入需要申请证书的域名（单域名证书），必填项，例如：www.bt.cn" class="bt-input-text mr5 ssl_site_name_rc" type="text" style="width:400px" value=""></div></div>\
            <ul class="help-info-text c7">\
                    <li> 申请之前，请确保域名已解析，如未解析会导致审核失败(包括根域名)</li>\
                    <li>申请www.bt.cn这种以www为二级域名的证书，需绑定并解析顶级域名(bt.cn)，否则将验证失败</li>\
                    <li>SSL证书可选名称赠送规则：</li>\
                    <li>1、申请根域名(如：bt.cn),赠送下一级为www的域名(如：www.bt.cn)</li>\
                    <li>2、申请当前host为www的域名（如：www.bt.cn）,赠送上一级域名，(如: bt.cn)</li>\
                    <li>3、申请其它二级域名，(如：app.bt.cn)，赠送下一级为www的域名 (如：www.app.bt.cn)</li>\
                </ul >\
            </div>',
      success: function () {

      },
      yes: function (layers, index) {
        layer.close(layers);
        $('#' + box).val($('.ssl_site_name_rc').val())
      }
    })
  },

  /**
   * @descripttion: 选择站点
   * @author: Lifu
   * @Date: 2020-08-14
   * @param {String} box 输出时所用ID
   * @return: 无返回值
   */
  select_site_list: function (box, code) {
    var _optArray = [],
      all_site_list = [];
    $.post('/data?action=getData', {
      tojs: 'site.get_list',
      table: 'domain',
      limit: 10000,
      search: '',
      p: 1,
      order: 'id desc',
      type: -1
    }, function (res) {
      var _tbody = '';
      if (res.data.length > 0) {
        $.each(res.data, function (index, item) {
          _body = '<tr>' +
            '<td>' +
            '<div class="box-group" style="height:16px">' +
            '<div class="bt_checkbox_groups"></div>' +
            '</div>' +
            '</td>' +
            '<td><span class="overflow_style" style="width:210px">' + item['name'] + '</span></td>'

            +
            '</tr>'

          if (code.indexOf('wildcard') > -1) {
            if (item['name'].indexOf('*.') > -1) {
              all_site_list.push(item['name'])
              _tbody += _body;
            }
          } else {
            all_site_list.push(item['name'])
            _tbody += _body;
          }
        })
        if (all_site_list.length == 0) {
          _tbody = '<tr><td colspan="2">暂无数据</td></tr>'
          if (code.indexOf('wildcard') > -1) {
            _tbody = '<tr><td colspan="2">暂未绑定泛域名，请先添加.</td></tr>'
          }
        }
      } else {
        _tbody = '<tr><td colspan="2">暂无数据</td></tr>'
      }

      layer.open({
        type: 1,
        closeBtn: 2,
        title: '选择站点',
        area: '600px',
        btn: ['确认', '取消'],
        content: '<div class="pd20 dynamic_head_box"><div class="line"><input type="text" name="serach_site" class="bt-input-text" style="width: 560px;" placeholder="支持字段模糊搜索"></div>\
                <div class="bt-table dynamic_list_table">\
                    <div class="divtable" style="height:281px">\
                        <table class="table table-hover">\
                            <thead>\
                                <th width="30">\
                                    <div class="box-group" style="height:16px">\
                                        <div class="bt_checkbox_groups" data-key="0"></div>\
                                    </div>\
                                </th>\
                                <th>域名</th>\
                            </thead>\
                            <tbody class="dynamic_list">' + _tbody + '</tbody>\
                        </table>\
                    </div>\
                </div>\
                <ul class="help-info-text c7">\
                    <li> 申请之前，请确保域名已解析，如未解析会导致审核失败(包括根域名)</li>\
                    <li>申请www.bt.cn这种以www为二级域名的证书，需绑定并解析顶级域名(bt.cn)，否则将验证失败</li>\
                    <li>SSL证书可选名称赠送规则：</li>\
                    <li>    1、申请根域名(如：bt.cn),赠送下一级为www的域名(如：www.bt.cn)</li>\
                    <li>    2、申请当前host为www的域名（如：www.bt.cn）,赠送上一级域名，(如: bt.cn)</li>\
                    <li>    3、申请其它二级域名，(如：app.bt.cn)，赠送下一级为www的域名 (如：www.app.bt.cn)</li>\
                </ul >\
                </div> ',
        success: function () {

          // 固定表格头部
          if (jQuery.prototype.fixedThead) {
            $('.dynamic_list_table .divtable').fixedThead({
              resize: false
            });
          } else {
            $('.dynamic_list_table .divtable').css({
              'overflow': 'auto'
            });
          }
          //检索输入
          $('input[name=serach_site]').on('input', function () {
            var _serach = $(this).val();
            if (_serach.trim() != '') {
              $('.dynamic_list tr').each(function () {
                var _td = $(this).find('td').eq(1).html()
                if (_td.indexOf(_serach) == -1) {
                  $(this).hide()
                } else {
                  $(this).show()
                }
              })
            } else {
              $('.dynamic_list tr').show()
            }
          })

          // 单选设置
          $('.dynamic_list').on('click', '.bt_checkbox_groups', function (e) {
            var _tr = $(this).parents('tr');
            if ($(this).hasClass('active')) {
              $(this).removeClass('active');

            } else {
              $('.dynamic_list .bt_checkbox_groups').removeClass('active');
              $(this).addClass('active');
              _optArray = [_tr.find('td').eq(1).text()]
            }
            e.preventDefault();
            e.stopPropagation();
          })
          // tr点击时
          $('.dynamic_list').on('click', 'tr', function (e) {
            $(this).find('.bt_checkbox_groups').click()
            e.preventDefault();
            e.stopPropagation();
          })
        },
        yes: function (layers, index) {
          var _olist = []
          if (_optArray.length > 0) {
            $.each(_optArray, function (index, item) {
              if ($.inArray(item, _olist) == -1) {
                _olist.push(item)
              }
            })
          }
          layer.close(layers);
          $('#' + box).val(_olist.join('\n'))
          $('textarea[name=lb_site]').focus();
        }
      })
    })
  },
  site_waf: function (siteName) {
    try {
      site_waf_config(siteName);
    } catch (err) {
      site.no_firewall();
    }

  },
  web_edit: function (obj) {
    var _this = this,
      item = obj;
    bt.open({
      type: 1,
      area: ['780px', '722px'],
      title: lan.site.website_change + '[' + item.name + ']  --  ' + lan.site.addtime + '[' + item.addtime + ']',
      closeBtn: 2,
      shift: 0,
      content: "<div class='bt-form'><div class='bt-w-menu site-menu pull-left' style='height: 100%;'></div><div id='webedit-con' class='bt-w-con webedit-con pd15'></div></div>"
    });
    setTimeout(function () {
      var webcache = bt.get_cookie('serverType') == 'openlitespeed' ? {
        title: 'LS-Cache',
        callback: site.edit.ols_cache
      } : '';
      var menus = [{
          title: '域名管理',
          callback: site.edit.set_domains
        },
        {
          title: '子目录绑定',
          callback: site.edit.set_dirbind
        },
        {
          title: '网站目录',
          callback: site.edit.set_dirpath
        },
        {
          title: '目录保护',
          callback: site.edit.set_dirguard
        },
        {
          title: '应用程序池',
          os: 'Windows',
          callback: site.edit.set_apppool
        },
        {
          title: '错误页',
          os: 'Windows',
          callback: site.edit.set_error_page
        },
        {
          title: '流量限制',
          callback: site.edit.limit_network
        },
        {
          title: '伪静态',
          callback: site.edit.get_rewrite_list
        },
        {
          title: '默认文档',
          callback: site.edit.set_default_index
        },
        {
          title: '配置文件',
          callback: site.edit.set_config
        },
        {
          title: 'SSL',
          callback: site.edit.set_ssl
        },
        {
          title: 'PHP版本',
          callback: site.edit.set_php_version
        },
        {
          title: 'Tomact',
          os: 'Linux',
          callback: site.edit.set_tomact
        },
        {
          title: '重定向',
          callback: site.edit.set_301
        },
        {
          title: '反向代理',
          callback: site.edit.set_proxy
        },
        {
          title: '防盗链',
          callback: site.edit.set_security
        },
        {
          title: '响应日志',
          callback: site.edit.get_site_logs
        }
      ]
      if (webcache !== '') menus.splice(3, 0, webcache);
      for (var i = 0; i < menus.length; i++) {
        var men = menus[i];
        if (men.os == undefined || men.os == bt.os) {
          var _p = $('<p>' + men.title + '</p>');
          _p.data('callback', men.callback);
          $('.site-menu').append(_p);
        }
      }
      $('.site-menu p').click(function () {
        $('#webedit-con').html('');
        $(this).addClass('bgw').siblings().removeClass('bgw');
        var callback = $(this).data('callback')
        if (callback) callback(item);
      });
      site.reload(0);
    }, 100);
  }
}